<html>
<head>
<title>测试JQuery</title>
<meta charset = "utf-8"/>
<style>
.class_1{
background-color: red;
}
</style>
<script type = "text/javascript" src = "../JQuery/jquery.js"></script>
<script language = "javascript">
$(document).ready(function(){
window.alert("Hello JQuery!");
});
//这里触发事件后不能输出您好
$('#test').click(function(){
window.alert('您好');
});
</script>
</head>
<body>
<input class = "class_1" type = "button" id="test" value = "点击测试"/>
</body>
</html>你的是能用 click事件的
$(document).ready(function(){
window.alert("Hello JQuery!");
//把代码放在 ready 方法里面 才起作用 因为要等文档加载完成 才能找到 test这个元素
//这里触发事件后不能输出您好
$('#test').click(function(){
window.alert('您好');
});
});可是我改成你这样也是不显示???
<html>
<head>
<title>测试JQuery</title>
<meta charset = "utf-8"/>
<style>
.class_1{
background-color: red;
}
</style>
<script type = "text/javascript" src = "../JQuery/jquery.js"></script>
</head>
<body>
<input class = "class_1" type = "button" id="test" value = "点击测试"/>
<script language = "javascript">
$(document).ready(function(){
alert("Hello JQuery!");
});
//这里触发事件后不能输出您好
$('#test').click(function(){
alert('您好');
});
</script>
</body>
</html>加载顺序问题。
jquery.js路径正确吗?window.alert这里的window可以省略。
以上就是JQuery不能使用click事件的问题解决的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号