我的.html里面有以下代码:
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id = "test"></div>
<a href="http://jquery.com/"></a>
<script src="jquery.js"></script>
<script>
$("#test").click(function(){
alert("works");
});
</script>
</body>
</html>
但是,当我运行程序并点击“#test”时,没有任何反应。 我做错了吗?
旁注:我正在使用Sublime Text 2
答案 0 :(得分:0)
您只需使用jquery CDN
进行尝试<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
$("#test").click(function(){
alert("works");
});
</script>
这可能有助于你
答案 1 :(得分:0)
首先检查你的Jquery路径是否正确
<script src="check_your_path/jquery.js"></script>
<script>
$( document ).ready(function() {
$("#test").click(function(){
alert("works");
});
});
</script>
答案 2 :(得分:0)
- 首先检查jquery文件的给定路径是否正确 - 你的div是空的,所以把东西放在
中 <div id="test"> Click Me </div>
现在它完美无缺
这是我的代码:
<!doctype html>
<html>
<head>
<title>Test</title>
</head>
<body>
<div id ="test">click me</div>
<a href="http://jquery.com/"></a>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$("#test").click(function(){
alert("works");
});
</script>
</body>
</html>
和Dude总是把你的包含文件像js,css放在<head></head>
中
所以正确的结构是
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script>
$("#test").click(function(){
alert("works");
});
</script>
</head>
<body>
<div id ="test">click me</div>
<a href="http://jquery.com/"></a>
</body>
</html>