您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
免费发信息
三六零分类信息网 > 南平分类信息网,免费分类信息发布

JQuery不能使用click事件的问题解决

2024/6/7 17:58:21发布15次查看
jquery中怎么不能用click事件
<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事件的问题解决的详细内容。
南平分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录