链接到外部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.
更多推荐
发布评论