每当我将脚本放入与 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>
脚本.js
$(document).ready(function(){
$('p').click(function(){
$(this).hide();
});
});
有人知道我做错了什么吗?
最佳答案
scr
不是 src
。使用a validator确保您没有拼错属性名称。
关于javascript - 链接到外部 js 时 jquery 未运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27337284/