我有一个类似这样的东西:http://jsfiddle.net/PTcw8/4/
<div id="container">
<a href="#" onclick="javascript:alert('inline'); return false;"> show me </a>
<br />
<input type="button" value="click to change the links onclick event" onclick="javascript:changeOnClick(); return false;" />
</div>
function changeOnClick() {
$("#container a").unbind('click');
$("#container a").on('click', function() {
alert("changed on the fly");
})
}
这个链接有一个内联的onclick事件,我无法解除它并绑定一个新的处理程序,它们只是因为某种原因堆叠在一起。
不能解除内联处理程序吗?
onclick
,而是使用addEventListener
。这样就没有值可以被覆盖了。 - pimvdb