2009-11-29 247 views
0

我有一个html页面,其中包含一个这样的按钮。jquery :: submit selector not working?

<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

@trike所示的代码快,做的答案提供解决您的问题? – 2009-11-29 19:45:22

回答

2

根据浏览器的不同,传统意义上的内联消息不会“绑定”。因此,您不能致电unbind将其删除。这是您需要覆盖内联函数的代码:

$(':image,:reset,:button,:submit').each(function(){ 
    this.onclick = null; 
    $(this).bind('click',function(e){ alert("clicked!"); }); 
}); 

而您的其他代码应该正常运行。

编辑这可能是更多的“jQuery的一样:”如果这样写的,它可能会跑的比上面:

$(':image,:reset,:button,:submit') 
    .removeAttr('onclick') 
    .click(function(e){ alert("clicked!"); });