我有一个html页面,其中包含一个这样的按钮。
<input id="qsbButton" class="btn" type="submit" tabindex="10" value="Search" name="qsbButton" onclick="searchSubmitted();return true;"/>
$(':image,:reset,:button,:submit').unbind("click")
.bind('click',function(e){
alert("clicked!");
});
$('input:not(:submit),textarea').change(function(e){
alert("typed something!");
});
我希望收到“点击!”警报但没有...没有错误消息。
答案 0 :(得分:2)
根据浏览器的不同,内联消息不会受传统意义上的“约束”。因此,您无法调用unbind
来删除它们。这是覆盖内联函数所需的代码:
$(':image,:reset,:button,:submit').each(function(){
this.onclick = null;
$(this).bind('click',function(e){ alert("clicked!"); });
});
其余的代码应该正常运行。
编辑如果以这种方式编写,这可能更像“jQuery-like”,它可能比上面显示的代码运行得更快。:
$(':image,:reset,:button,:submit')
.removeAttr('onclick')
.click(function(e){ alert("clicked!"); });