简体   繁体   English

为什么我必须重命名javascript文件才能使新功能正常工作

[英]Why do I have to rename my javascript file to get my new functions to work

I recently added this function to my .js file for my website: 我最近将此功能添加到我的网站的.js文件中:

function toggleActive() {

    $("#terminalLabel").addClass("active");

}

for: 对于:

<input id='terminal' class='hidden' type='checkbox' placeholder='Terminal Option' name='terminal[0][]'>
<label id='terminalLabel' class='btn btn-default' for='terminal2' onclick="toggleActive()">Terminal Option</label>

I kept getting an uncaught reference error when I would try to activate the function, but didn't know why. 当我尝试激活该功能时,我一直收到未捕获的参考错误,但不知道为什么。

I put the function in script tags to see if it worked, and it did. 我将该函数放在脚本标签中,以查看它是否起作用,并且确实起作用。 I added a different function to the button that was already defined in the same .js file that I made this new function, and that function worked. 我向该新功能所在的.js文件中已定义的按钮添加了一个不同的功能,该功能正常工作。

Then I changed the name of the file from form.js to form1.js and had my site call it up, and then the function just worked. 然后,我将该文件的名称从form.js更改为form1.js,并让我的网站对其进行了调用,然后该函数正常工作了。 Why is this? 为什么是这样?

在谷歌浏览器中,按F12键,然后按设置图标(如齿轮一样锁定),并在常规下选中禁用缓存选项(您需要打开开发选项以使其处于活动状态),然后右键单击刷新图标并单击清除缓存,然后单击清除缓存。您也可以在网址末尾添加?_ = 1,它会显示为新版本,并在您进行更改时增加数字。

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

相关问题 Java 脚本功能不起作用,如何将我的 javascript 文件添加到 html 并使其工作 - Java Script Functions Don't work and How do i add my javascript file to html and get it to work 如何在我的Javascript文件中使用CSS类? - How do I get a CSS class to work in my Javascript file? 我无法让我的 JavaScript 代码在我的 HTML 文件中工作 - I can not get my JavaScript code to work in my HTML file 为什么我的Javascript函数不起作用? - Why won't my Javascript functions work? 在脚本标记中执行一些javascript后,为什么在html文件中有此文本“ undefined”? - Why do I have this text “undefined” in my html file after I execute some javascript in script tag? 您是否知道为什么我的代码无法正常工作,而单击时却无法获取数字? - Do you have any idea why my code does not work and I can not get the numbers while clicking 为什么必须重新加载页面才能使JS事件正常工作? - Why do I have to reload the page for my JS event to work? 为什么其他JavaScript文件在我的PHP文件中不起作用? - Why do other JavaScript files not work in my PHP file? 为什么我必须在Javascript中转义第二个$符号? - Why do I have to escape and second $ symbol in my Javascript? 为什么我必须在React的匿名函数中包装onClick属性的函数? - Why do I have to wrap the functions of my onClick attributes in anonymous functions in React?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM