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事件的问题解决的详细内容,更多请关注Work网其它相关文章!

09-16 14:29