简体   繁体   English

onClick()不起作用

[英]onClick() Not Working

I have two links on my html page which when clicked runs a script using 'onClick'. 我的html页面上有两个链接,当单击这些链接时,它们会使用“ onClick”运行脚本。 the code worked perfectly before but after I added some code then removed it, it has stopped working. 该代码之前运行良好,但是在我添加了一些代码然后将其删除之后,该代码已停止工作。

Link 链接

<a id="log" class="btn btn-xs" href="#" onclick="Options.js">Change Log</a>

Options.js Options.js

document.getElementById('log').addEventListener('click', showLog);

function showLog() {
var log = window.open("", "title", "srollbars=0, width=440, height=620");
var src = "../changelog/changelog.txt";

log.document.write('<p><iframe src="'+src+'" width=430 height=600 frameborder=0></iframe></p>');
}

The code seems slightly finicky. 该代码似乎有点挑剔。 Thanks for any help! 谢谢你的帮助!

<a id="save" class="btn btn-xs" href="#" onclick="Options.js">Change Log</a>

Should be 应该

<a id="save" class="btn btn-xs" href="#" onclick="showLog()">Change Log</a>

You've referenced the script file not the function, providing you've included your options.js somewhere in your html document 您已引用脚本文件而非函数,前提是您已将options.js包含在html文档中

Ie the snippet below is present in the html document somewhere 即下面的代码段出现在html文档的某个地方

<script src="js/Options.js"></script> 

onClick expects a function, not a file. onClick需要功能,而不是文件。 Import your file first, then call your function like showLog(); 首先导入文件,然后调用showLog()之类的函数; in the onclick segment. 在onclick段中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM