开发者

jQuery seems to have an enable function, but not a disable function. Why?

Until now I was using the following to disable/enable form fields -

$('#fieldid').attr('disable','disable');
$('#fieldid').removeAttr('disable');

And that got the job done. But yesterday, I absent-mindedly typed the following开发者_开发知识库 to enable the field -

$('#fieldid').enable();

And it worked! I silently kicked myself for not trying the the handy 'enable'/'disable' functions built into jQuery (or so I thought), and proceeded to change the line to disable to -

$('#fieldid').disable();

And to my surprise, that did NOT work.

Am I missing something? Why is the enable() function defined but the disable() function is not? And even weirder, I could find no mention of either enable() or disable() in the jquery docs. Does anyone have any explanations?

I'm using jQuery 1.6.


jQuery does not support an enable() method out of the box (and the disable HTML attribute does not exist either, but that might only be a typo in your question).

Maybe you're using a plug-in that provides that feature? If that's the case, try passing false to the enable() method to disable a field:

$('#fieldid').enable(false);


Looks like it's available via the disable plugin. As for why it's not included out of the box, I can only assume that it was left out as the functionality was already covered by .attr()


I have read through the jquery code and the documentation but couldn't find any indicition of am enable function, are you sure the box isn't already enabled?

I created a jsfiddle to check:

http://jsfiddle.net/Zy3tW/1/

$(document).ready(function(){
    $("#textinput").enable();
});

<input id="textinput" type="text" disabled="disabled" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜