开发者

How to swap a disabled option DOM element to enabled?

I have a list with enabled and disabled option. I do know how to disable an option element but what I don't know how to enable it again.

<select size="1" id="x">
  <option value="47" disabled="disabled">Value 47</option>
  ...


selectEleme开发者_运维技巧nt.options[i].disabled = 'disabled';
// ... how to enable?

It should be done with Plain Javascript and no JavaScript Framework. (I wish I could use Prototype or a similar framework but I cannot introduce one of them.)


Use setAttribute and removeAttribute:

selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");


The DOM object's property is a boolean value, that should be set to true or false:

selectElement.options[i].disabled = false;

Also see Boolean HTML Attributes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜