Jquery click event doesn't work

时光总嘲笑我的痴心妄想 提交于 2019-12-02 08:38:31

问题


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>

回答1:


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");
    });

});


来源:https://stackoverflow.com/questions/14006040/jquery-click-event-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!