问题
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