开发者

How to swap a disabled option DOM element to enabled?

开发者 https://www.devze.com 2023-01-27 09:52 出处:网络
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.

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

精彩评论

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