Jquery点击事件不起作用

LK *_*ung 1 jquery click

单击test2的test1时没有结果

<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>
Run Code Online (Sandbox Code Playgroud)

Adi*_*dil 7

您需要将事件注册放在document.ready()中,以便您尝试绑定事件的元素已准备好运行到您的脚本中.

$(document).ready(function(){

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

});
Run Code Online (Sandbox Code Playgroud)