friend ,
我注意到在 Firefox v23.0.1 中,HTMLElement(input,button..etc) 的 hasOwnProperty
不起作用,
button1.hasOwnProperty('id') = false
我用 for in 来检查:
var str1 = '';
for (pp in button1) {
if (button1.hasOwnProperty(pp)) {
str1 += (',' + pp);
}
}
alert(str1);//nothing here
但在 chrome 中 hasOwnProperty 运行良好。
你知道这是一个错误吗?
最佳答案
根据规范,“id”属性在 HTMLElement.prototype 或 Element.prototype 上(取决于规范版本)。
Firefox 做对了。 Chrome 将所有属性直接放在对象上。
http://dev.w3.org/2006/webapi/WebIDL/#es-attributes http://dev.w3.org/2006/webapi/WebIDL/#ecmascript-binding
关于javascript - hasOwnProperty HTMLElement 火狐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18478913/