Jquery 如何删除按钮的现有javascript函数
如果要删除单击事件,可以使用Jquery 如何删除按钮的现有javascript函数,jquery,jquery-validate,Jquery,Jquery Validate,如果要删除单击事件,可以使用 $("#mybutton").onclick(function(){ //$("#mybutton").removeattr("onClick",""); }) 使用unbind删除事件侦听器 $('#mybutton').unbind('click'); (另外,$()。如果需要删除onclick属性“按需”使用,请单击,而不是onclick) 再次查看选择器。您需要查询代码段的ID 尝试选择mybutton作为ID,实际上是元素的名称。您不能使用unbi
$("#mybutton").onclick(function(){
//$("#mybutton").removeattr("onClick","");
})
使用
unbind
删除事件侦听器
$('#mybutton').unbind('click');
(另外,
$()。如果需要删除onclick
属性“按需”使用,请单击,而不是onclick
)
再次查看选择器。您需要查询代码段的ID
尝试选择mybutton
作为ID,实际上是元素的名称。您不能使用unbind
删除onclick处理程序unbind
仅适用于jQuery绑定的事件处理程序。可以这样做:
$('#id_button').removeAttr('onclick').click(function(){
});
演示:是的,您的问题是什么?mybutton
是元素的名称属性,您需要查询\id\u button
。谢谢Andy,它为meYep解决了,我会采用jAndy解释的方法,因为unbind在我的应用程序中不起作用。@jAndy-他没有添加HTML代码来明确说明在我回答时这是一个内联事件。
$("#mybutton").click(function(){
$(this).unbind("click");
})
$('#id_button').removeAttr('onclick').click(function(){
});
document.getElementById("id_button").onclick = null;
// you can still get the element using the jQuery shorthand though
// the point is to get at the DOM element's onclick property
$("#id_button")[0].onclick = null;