问题
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>
...
selectElement.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.)
回答1:
Use setAttribute and removeAttribute:
selectElement.options[i].setAttribute("disabled", "disabled");
selectElement.options[i].removeAttribute("disabled");
回答2:
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.
来源:https://stackoverflow.com/questions/4315197/how-to-swap-a-disabled-option-dom-element-to-enabled