Jquery点击事件不工作 [英] Jquery click event doesn't work

查看:118
本文介绍了Jquery点击事件不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击test2的test1时没有结果

no result occur when i click test1 of test2

<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

    <script type="text/javascript">
    $(".trigger").click(function(event){
        console.log("d");
    });
    </script>
</head>
<body>
    <a href="#" class="trigger">Test1</a>
    <a href="javascript:void(0)" class="trigger" >Test2</a>
</body>
</html>


推荐答案

您需要将事件注册到 document.ready() ,以便您尝试绑定事件的元素已准备好到您的脚本。 / p>

You need to put the event registration in document.ready() so that the element you are trying to bind the event are ready to your script.

$(document).ready(function(){

  $(".trigger").click(function(event){
        console.log("d");
    });

});

这篇关于Jquery点击事件不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆