如何将禁用的选项DOM元素交换为启用? [英] How to swap a disabled option DOM element to enabled?

查看:120
本文介绍了如何将禁用的选项DOM元素交换为启用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个有启用和禁用选项的列表。我知道如何禁用选项元素,但是我不知道如何重新启用它。

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


selectElement.options [i] .disabled ='disabled';
// ...如何启用?

应该使用纯Java和JavaScript框架完成。 (我希望我可以使用原型或类似的框架,但我不能介绍其中的一个。)

解决方案

使用 setAttribute removeAttribute

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


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.)

解决方案

Use setAttribute and removeAttribute:

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

这篇关于如何将禁用的选项DOM元素交换为启用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆