【发布时间】:2014-12-26 07:09:31
【问题描述】:
我在浏览器中遇到了一个非常奇怪的问题:我有一个 HTMLElement elt 是一个图像,但 elt.getAttribute 是未定义的,尽管 elt.__proto__ 包含一个 getAttribute 方法。
我检查了很多东西:
elt.nodeType => 1
elt.__proto__ => HTMLImageElement {click: function, getAttribute: function, setAttribute: function, removeAttribute: function, getAttributeNode: function…}
elt.__proto__.getAttribute => function getAttribute() { [native code] }
elt.getAttribute => undefined
elt.setAttribute => function setAttribute() { [native code] }
elt.getAttributeNS => function getAttributeNS() { [native code] }
elt.getAttributeNode => function getAttributeNode() { [native code] }
elt.getAttributeNodeNS => function getAttributeNodeNS() { [native code] }
typeof elt => object
知道这可能来自哪里吗?我不知道这是从哪里来的。
【问题讨论】:
-
提供您的验证码
-
代码太多了。我应该将我的问题转变为:“当对象是 dom 元素时,为什么有人可以做
object.setAttribute = undefined”
标签: javascript jquery dom