Ⅰ 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>