链接到外部js时jquery没有运行(jquery not running when linked to an external js)

编程入门 行业动态 更新时间:2024-10-17 21:19:10
链接到外部js时jquery没有运行(jquery not running when linked to an external js)

每当我将脚本放在与script.js相同的文件夹中的另一个文件中时,它就不会运行。 它仅在我将代码包含在脚本标记中时运行。

我用这个简单的jquery代码试了一下。 每当第三个脚本标记被取消注释时,它都可以工作,但我现在所拥有的设置不会运行。

HTML

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" scr="script.js"></script> // <!-- doesn't run --> <!--script> // <!-- only runs inside the html file --> $(document).ready(function(){ $('p').click(function(){ $(this).hide(); }); }); </script--> </head> <body> <p>Click to hide.</p> </body> </html>

的script.js

$(document).ready(function(){ $('p').click(function(){ $(this).hide(); }); });

有谁知道我做错了什么?

Whenever I put the script in another file in the same folder as script.js, it doesn't run. It only runs when I include my code in the script tag.

I tried it out with this simple jquery code. Whenever the third script tag is uncommented, it works, but the set up I have right now doesn't run.

HTML

<!DOCTYPE html> <html> <head> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript" scr="script.js"></script> // <!-- doesn't run --> <!--script> // <!-- only runs inside the html file --> $(document).ready(function(){ $('p').click(function(){ $(this).hide(); }); }); </script--> </head> <body> <p>Click to hide.</p> </body> </html>

script.js

$(document).ready(function(){ $('p').click(function(){ $(this).hide(); }); });

Does anyone know what I am doing wrong?

最满意答案

scr不是src 。 使用验证器确保您没有拼错属性名称。

scr is not src. Use a validator to make sure you haven't misspelt attribute names.

更多推荐

本文发布于:2023-08-06 22:55:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1456653.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   js   jquery   external   linked

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!