我有一个按钮,最初是禁用的:
<button disabled="disabled">Lorem ipsum</button>
对于这个按钮,
button.getAttribute('disabled')
返回 "disabled"
。然而,当我使用JavaScript启用此按钮时:button.disabled = false;
然后button.getAttribute('disabled')
开始返回null
。
实时演示: http://jsfiddle.net/Rhj3c/1/
为什么会这样?.getAttribute()
不应该返回原始HTML源代码中的值吗?那我如何确定按钮在原始HTML源代码中是否已禁用?