例子如下:
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <script src="https://code.jquery.com/jquery-1.11.3.js"></script> 5 <meta charset="utf-8"> 6 <title>JS Bin</title> 7 </head> 8 <body> 9 <ul> 10 <li class="li"> 11 <p>这里是li里面的p</p> 12 </li> 13 <li class="li"> 14 <p>这里是li里面的p</p> 15 </li> 16 <li class="li"> 17 <p>这里是li里面的p</p> 18 </li> 19 <li class="li"> 20 <p>这里是li里面的p</p> 21 </li> 22 </ul> 23 <script> 24 $(function(){ 25 $(document).on("click", ".li", function(e){ 26 console.log(e.currentTarget.nodeName); 27 console.log(e.target.nodeName); 28 }); 29 }); 30 </script> 31 </body> 32 </html>
输出结果如下:
"LI"
"P"
e.currentTarget 捕获到的是该绑定事件的元素,
而e.target则捕获到的是鼠标点击的节点