jquery如何判断元素是否被点击_百度知道


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选择器的原因,所以一定要指定父级,否则会执行多次。




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM