通过属性或setAttribute设置属性 [英] Setting a property via property or setAttribute
问题描述
A)element.setAttribute(disabled,true);
B)element.disabled = true;
他们都似乎禁用了FF 4中的输入[text]元素。
一般来说...
使用属性。很长一段时间(直到版本7或8 IIRC)Internet Explorer已经严重破坏了 setAttribute
的实现,该属性将不属于该属性(经典的故障点为 class
,因为没有类
属性(它是 className
)
在这种情况下,特别是... element.setAttribute(disabled,true);
是错误的应该是 element.setAttribute(disabled,disabled);
Is one of these more preferable than the other? Why? How about performance--if these are being called thousands of times?
A) element.setAttribute("disabled", true);
B) element.disabled = true;
They both seem to disable an input[text] element in FF 4.
In general…
Use properties. For a long time (until version 7 or 8 IIRC) Internet Explorer had a seriously broken implementation of setAttribute
that would set the property not the attribute (the classic point of failure was class
since there is no class
property (it is className
).
In this case in particular… element.setAttribute("disabled", true);
is wrong. It should be element.setAttribute("disabled", "disabled");
这篇关于通过属性或setAttribute设置属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!