cle*_*tus 36
这是我喜欢扩展jQuery的一个领域:
$.fn.disable = function() {
return this.each(function() {
if (typeof this.disabled != "undefined") this.disabled = true;
});
}
$.fn.enable = function() {
return this.each(function() {
if (typeof this.disabled != "undefined") this.disabled = false;
});
}
Run Code Online (Sandbox Code Playgroud)
然后你可以这样做:
$("#button").disable();
$("#button").enable();
Run Code Online (Sandbox Code Playgroud)
我发现自己很多都禁用/启用控件.
Pet*_*r J 10
在脚本开头的某处(可能是按钮的单击事件),将按钮的disabled属性设置为true:
$("#mybutton").attr("disabled", true);
Run Code Online (Sandbox Code Playgroud)
然后,完成后,删除该属性:
$("#mybutton").removeAttr("disabled");
Run Code Online (Sandbox Code Playgroud)
编辑:
如果你想得到(略微)幻想,在你工作的时候改变按钮的文字.如果是图像按钮,您可以将src更改为友好的"请稍候"消息.这是按钮文本版本的示例:
$("#mybutton").click(function() {
var origVal = $(this).attr("value");
$(this).attr("value", "Please wait...");
$(this).attr("disabled", true);
//Do your processing.
$(this).removeAttr("disabled");
$(this).attr("value", origVal);
});
Run Code Online (Sandbox Code Playgroud)