Jquery 如何捕获所有子元素中的单击?
问题很简单,但我做不到。。。这是我的代码:Jquery 如何捕获所有子元素中的单击?,jquery,Jquery,问题很简单,但我做不到。。。这是我的代码: jQuery('nav').on('click', 'a', function(event){ console.log(jQuery(this)); }); nav必须是类或Id,nav似乎不是标准标记 如果是类名 jQuery('.nav').on('click', 'a', function(event){ console.log(jQuery(this)); }); 如果是身份证 jQuery('#nav').on('cl
jQuery('nav').on('click', 'a', function(event){
console.log(jQuery(this));
});
nav
必须是类或Id,nav似乎不是标准标记
如果是类名
jQuery('.nav').on('click', 'a', function(event){
console.log(jQuery(this));
});
如果是身份证
jQuery('#nav').on('click', 'a', function(event){
console.log(jQuery(this));
});
这里有一个现场演示:您的代码看起来不错。。。。但我认为您缺少
文档.ready
功能
试试这个
jQuery(function(){ //ready function
jQuery('nav').on('click', 'a', function(event){
console.log(jQuery(this));
});
});
html5有元素
nav
,我use@bipen只有长ul
和li
列表