更新时间:2022-02-02 01:29:41
那是因为事件冒出来了,你可以使用事件的
对象: stopPropagation
方法
That's because events bubble up, you can use stopPropagation
method of the event
object:
$(".contry-list").on("click", function(event){
event.stopPropagation();
alert("clicked on country's list");
});
如果要动态生成 li
元素您应该委派活动:
If you are generating the li
elements dynamically you should delegate the event:
$(document).on('click', '.coutry-list', function(){
console.log('li element is clicked');
})