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