Jquery 删除与元素关联的事件

Jquery 删除与元素关联的事件,jquery,mouseevent,Jquery,Mouseevent,我有5个img标签,比如 <img id="test-btn" src="image/btn1.png" onmouseover="this.src='image/btn2.png'" onmousedown="this.src='image/btn1.png'" onmouseup="this.src='image/btn2.png'" onmouseout="this.src='image/btn1.png'" onclick="uponClickingTestBtn()" style

我有5个img标签,比如

<img id="test-btn" src="image/btn1.png" onmouseover="this.src='image/btn2.png'" onmousedown="this.src='image/btn1.png'" onmouseup="this.src='image/btn2.png'" onmouseout="this.src='image/btn1.png'" onclick="uponClickingTestBtn()" style="heignt:15px;width:30px;">


但没有起作用。我该怎么做?我还想在以后启用这些img单击。

将函数绑定设为NULL,单击时它不再执行任何操作。当然,我也为元素中的属性添加了删除

var button = document.getElementById('test-btn');
button.onmouseover = null;
button.removeAttribute('onmouseover');
在jQuery中,您只需
preventDefault
或返回
false
。有时人们两者都用。记住在tho末尾返回
false
,如果您仍想在单击中执行操作,否则函数将“中止”


要与代码保持一致,可以执行以下操作:

$('#test-btn :input').attr('onmousedown', null);
$('#test-btn :input').attr('onmouseover', null);
$('#test-btn :input').attr('onclick', null);
$('#test-btn :input').attr('onmouseout', null);
$('#test-btn :input').attr('onmouseup', null);

但是,不要考虑内联事件,并且去WTHjjQuery。())巫婆有一个函数()来删除事件。 如果仍然使用第一个解决方案,则可以按如下方式重新分配事件:

$('#test-btn :input').attr('onmouseover', "this.src='image/btn2.png'");
...
$('#test-btn').click(function(evt) {
    evt.preventDefault();

    return false;
});
$('#test-btn :input').attr('onmousedown', null);
$('#test-btn :input').attr('onmouseover', null);
$('#test-btn :input').attr('onclick', null);
$('#test-btn :input').attr('onmouseout', null);
$('#test-btn :input').attr('onmouseup', null);
$('#test-btn :input').attr('onmouseover', "this.src='image/btn2.png'");
...