<html> <body> <li onclick="javascript:alert(1);">11111 <li onclick="javascript:alert(2);"> 22222 <li id="li3" onclick="javascript:alert(3);"> 33333 </li> </li> </li> </body> <script> var li = document.getElementsByTagName(‘li‘); for(var i=1; i<=li.length; i++) { document.getElementsByTagName(‘li‘)[i].addEventListener(‘click‘,function(e){e.stopPropagation()},false);//阻止它的冒泡事件 } </script> </html>
时间: 2024-10-22 00:44:18