我正在尝试做一个简单的jQuery教程,但它不起作用.
<html>
<head>
<title></title>
<script type="text/javascript" src="jquery-1.3.2.js">
$(function() {
$('a').click(function() {
$('#box').fadeOut();
});
});
</script>
<style type="text/css">
#box
{ background: red;
width: 300px;
height: 300px;
}
</style>
</head>
<body>
<div id="box" ></div>
<a href="#">Click Me</a>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我复制并粘贴了jquery文件名:jquery-1.3.2
我看不出有什么问题?我正在使用Firefox.
Sco*_*ott 15
将您的点击事件代码放在不同的脚本块中.
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(function() {
$('a').click(function() {
$('#box').fadeOut();
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
您提交的错误让我想起了降级脚本标记
引用外部资源的脚本标记(通过src属性)不再能够执行标记本身嵌入的脚本.
首先,确保您jquery-1.3.2.js的目录中有.
然后,更改脚本标记:
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function() {
$('#box').fadeOut();
});
});
</script>
Run Code Online (Sandbox Code Playgroud)