JS阻止事件冒泡相容各瀏覽器
阿新 • • 發佈:2019-01-28
<!DOCTYPE html> <html> <head> <title>Document</title> </head> <body> <ul onclick="parent()"> <li>列表一 <ul onclick="child(event)"> <li>一</li> <li>二</li> </ul> </li> <li>列表二 <ul onclick="child(event)"> <li>一</li> <li>二</li> </ul> </li> </ul> <script type="text/javascript"> function parent(){ alert('parent'); } function child(){ alert('child'); var e= arguments.callee.caller.arguments[0] || event; if(e && e.stopPropagation){ e.stopPropagation(); }else if(window.event){ window.event.cancelBubble = true; } } </script> </body> </html>