每当我将脚本放在与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>
Run Code Online (Sandbox Code Playgroud)
的script.js
$(document).ready(function(){
$('p').click(function(){
$(this).hide();
});
});
Run Code Online (Sandbox Code Playgroud)
有谁知道我做错了什么?