js里多个addEventListener只执行一个,这个要怎么解决 50
varswitcher=this.element;if(switcher.addEventListener){switcher.addEventListener("cli...
var switcher= this.element;
if (switcher.addEventListener) {
switcher.addEventListener("click",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} else {
switcher.attachEvent("onclick",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
}
var song = this.element;
if (song.addEventListener) {
song.addEventListener("change",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} else {
song.attachEvent("onchange",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} 展开
if (switcher.addEventListener) {
switcher.addEventListener("click",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} else {
switcher.attachEvent("onclick",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
}
var song = this.element;
if (song.addEventListener) {
song.addEventListener("change",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} else {
song.attachEvent("onchange",
function() {
self.setPosition(true);
self.handleOnchange(self.element.checked)
})
} 展开
1个回答
展开全部
<script type="text/javascript">
var bind = function(e,t,fn){
if(e.addEventListener){
e.addEventListener(t, fn, false);
}else if(e.attachEvent){
e.attachEvent('on'+ t, fn);
}
}
</script>
<a href="#" id="test1">test</a>
<script type="text/javascript">
var e = document.getElementById('test1');
bind(e,'click',function(){alert(1)});
bind(e,'click',function(){alert(2)});
bind(e,'click',function(){alert(3)});
bind(e,'click',function(){alert(4)});
bind(e,'click',function(){alert(5)});
</script>
var bind = function(e,t,fn){
if(e.addEventListener){
e.addEventListener(t, fn, false);
}else if(e.attachEvent){
e.attachEvent('on'+ t, fn);
}
}
</script>
<a href="#" id="test1">test</a>
<script type="text/javascript">
var e = document.getElementById('test1');
bind(e,'click',function(){alert(1)});
bind(e,'click',function(){alert(2)});
bind(e,'click',function(){alert(3)});
bind(e,'click',function(){alert(4)});
bind(e,'click',function(){alert(5)});
</script>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询