今天有同事过来找我,,,input checkbox 区域太小了,想在外层TD上加上点击事件,但发现TD加了后,,,input也在里面,会被执行两次,记录一下,我写的DOME
<!DOCTYPE html> <html> <head> <meta charset="utf-8" name="viewport" content="width=device-width, initial-scale=1.0"> <title>福利社</title> <script type="text/javascript" src="/static/js/jquery.min.js"></script> </head> <body> <table><tr><td style="border: 1px solid #ff0000; width: 200px; height: 200px;"><input type="checkbox"> </td><td></td></tr></table> <script> $(function () { $(document).on("click", "td:first", function(event){ var input =$(this).find("input"); input.click(); event.stopImmediatePropagation(); }); $(document).on("click", "td:first input", function(event){ event.stopPropagation();// 阻止事件冒泡 }); }); </script> </body> </html>