Ⅰ js刪除一個ID元素的點擊事件
js本身可以用removeEventListener方法進行刪除
functionhandler(){
console.log(this);
}
document.getElementById("myBtn").addEventListener("click",handler,false);
document.getElementById("myBtn").removeEventListener("click",handler,false);
這里注意移除的函數要跟綁定的相同,所以不能用回匿名函數
用jquery的話,可以答用.off()方法或.unbind()方法,具體使用方法查下jquery API就行了,這里就不贅述了
Ⅱ js只有id才能綁定點擊事件嗎
不是的 你的id就等於getElementById 最後面的id 如果說你要用其他的 後面的id要改或者ById前面要加s
Ⅲ js如何循環添加點擊事件
$("."+data[i].ids+"").bind("click",function(){
$(this).data('divname',''+data[i].ids);
alert($(this).data('divname'));
});
這個自是在這個div上綁定了一個數據
對了 報錯內容發一下
Ⅳ javascript添加了一個div,給他一個id,用jq寫了這個id的點擊事件,但點擊後沒效果。
注意動態添加的元素的綁定方法
為動態添加的元素綁定事件需要用on()或者live()
直接用.click是沒有效果的
Ⅳ js 判斷標簽a被點擊了
//給a標簽綁定點擊事件
$("a").on("click",function(){
alert($(this).attr("id"));//彈出被點擊的a標簽的id
})
Ⅵ JS (javascript)中getID後,onclick觸發事件無效
把script腳本移到input後面就行了。像下面這樣:
<input type="button" id="button" value="點我">
<script type="text/javascript">
var a=document.getElementById('button')
a.onclick=function(){
alert("123");
}
</script>
Ⅶ 怎麼通過JS 給一個ID添加觸發事件
下面是jQuery的寫法
<!DOCTYPE html>
<html>
<head>
<style>p { color:red; }</style>
<script src=""$amp;>amp;$lt;/script>
<script>
$(document).ready(function () {
$("input").blur(function(){
alert(this.id);
});
});
</script>
</head>
<body>
<input type="text" id="inputid">
</body>
</html>