如何将已禁用的选项DOM元素交换为启用?

Tho*_*ler 0 html javascript xhtml dom

我有一个启用和禁用选项列表.我知道如何禁用选项元素,但我不知道如何再次启用它.

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


selectElement.options[i].disabled = 'disabled';
// ... how to enable?
Run Code Online (Sandbox Code Playgroud)

它应该使用Plain Javascript而不是JavaScript Framework.(我希望我可以使用Prototype或类似的框架,但我不能介绍其中一个.)

Gum*_*mbo 5

使用setAttributeremoveAttribute:

selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");
Run Code Online (Sandbox Code Playgroud)