<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body> <div>Div father <br> <p>click me</p> </div></body><script> var div=document.querySelector('div') div.onclick=function (event) { if(event.target.tagName=="P"){ var pElement=event.target pElement.onclick=function (event) { alert(' i am p') event.stopPropagation() } } }</script></html>
3 回答
已采纳
Caballarii
TA贡献1123条经验 获得超629个赞
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div>Div father <br> <p>click me</p> </div> </body> <script> var div=document.querySelector('div') div.onclick=function (event) { if(event.target.tagName=="P"){ alert(' i am p') event.stopPropagation() } } </script> </html>
干嘛要在p上再绑一次?多此一举
添加回答
举报
0/150
提交
取消