click冒泡到body

mac2022-06-30  21

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" /> 5 <title>test03</title> 6 </head> 7 <body> 8 <input type="button" id="myBtn" value="点击" /> 9 <script type="text/javascript" src="test03.js"></script> 10 </body> 11 </html> 1 document.body.onclick = function(event) { 2 console.log(event.currentTarget === document.body);//true 3 console.log(this === document.body);//true 4 console.log(event.target === document.getElementById("myBtn"));//true 5 };

转载于:https://www.cnblogs.com/qzsonline/archive/2012/05/25/2518656.html

相关资源:IOS设备上给body绑定click事件不生效的原因及解决办法
最新回复(0)