jQuery禁用按钮不起作用 [英] jQuery to disable button not work
问题描述
我曾经将事件绑定到我的按钮,如:
$(input [name = add])。live ( 点击,函数(){...});
但是我有另一个功能让它们启用和禁用,如:
$ $ p $ $ $ c $ RefreshBox(){
$(input [name = add])。each(function(){
if(...)
$(this).attr(disabled,disabled);
else
$(this).attr(disabled, );
})
}
事实并非如我所料。
PS:
jQuery 1.4.1
浏览器:IE8,禁用按钮后仍然是静止的能行得通。
浏览器:Chrome浏览器,禁用按钮成功。 您需要使用 prop 函数而不是 attr
:
$(this).prop(disabled,true);
和
$(this).prop(disabled,false);
编辑
OP使用jQuery pre 1.6.1,这就是为什么 I used to bind event to my button like : But I got another function to make them "enable" and "disabled" like : But in fact that it doesn't work as I expected. Buttons are still can be click and the event still works smoothly. PS:
jQuery 1.4.1
Browser: IE8 , after button disabled still can work.
Browser: Chrome, disabled button success. You'll want to use the prop function instead of and EDIT OP was using jQuery pre 1.6.1, which was why 这篇关于jQuery禁用按钮不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! attr
对于 disabled
不能正常工作的原因对于较老的IE)。虽然 prop 对于
被禁用
是首选,1.6.1 attr
应该(并且确实)工作。 $("input[name=add]").live("click",function(){...});
RefreshBox() {
$("input[name=add]").each(function(){
if(...)
$(this).attr("disabled","disabled");
else
$(this).attr("disabled","");
})
}
attr
:$(this).prop("disabled", true);
$(this).prop("disabled", false);
attr
for disabled
wasn't working quite right (for older IE). While prop
is preferred for disabled
, post 1.6.1 attr
should (and does) work as well.