我有这个simple HTML标记:getElementById无法按预期工作?
<form id="form" action="lalala">
<input type="text" id="action"/> //a reserved property name id
<input type="submit" id="submit"/> //same here
</form>
但是 - 运行:
alert(document.getElementById('form').action);
警报
,而不是 “LALALA” 像它应该。
似乎getElementById
的道具是不是直接访问
这是为什么? .....这实际上意味着我必须知道所有表单元素的道具(为了不向后代元素提供保留的道具ID)?
是否会发生两种道具和属性?因为我看到“行动”是一种财产,而不是一种属性。 (http://i.stack.imgur.com/WJPHB.png) –
@RoyiNamir - 我说:由于该特定属性映射到属性值,因此可以使用getAttribute和setAttribute来操作它。 (这在旧的IE中不起作用(它对那些对属性进行操作的方法有一个破坏的实现),并且对于其他一些属性(比如提交方法)不起作用)。 – Quentin