Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何捕获所有子元素中的单击?_Jquery - Fatal编程技术网

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
列表