1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
< div id = "parent" >
< a id = "a1" href = "javascript:void(0);" >点我</ a >
< a id = "a2" href = "javascript:void(0);" >点我吧</ a >
< input id = "b1" type = "button" value = "还是点我" ></ input >
< input id = "b2" type = "button" value = "那点你吧" ></ input >
</ div >
$("#parent *").click(function(e){ if(e.target == $("#a1")[0]){ alert("你点了链接一!"); }else if(e.target == $("#a2")[0]){ alert("你点了链接二!"); }else if(e.target == $("#b1")[0]){ alert("你点了按钮一!"); }else if(e.target == $("#b2")[0]){ alert("你点了按钮二!"); } }); |
可以试试我这个,因为jQuery选择器的原因,所以一定要指定父级,否则会执行多次。