Javascript - element.madeUpAttribute 与 IE8- 中的 element.getAt
Javascript - element.madeUpAttribute is the same as element.getAttribute('madeUpAttribute') in IE8-
如果我在一个元素上放置一个虚构的属性,那么element.madeUpAttribute
应该返回false。(在现代浏览器中确实如此。
但是在IE8中,它返回属性值,就像:element.getAttribute('madeUpAttribute')
有什么方法可以让它仅在浏览器支持属性时才返回属性值?
谢谢大家!
[更新]
下面是一个演示:http://jsfiddle.net/Daniel_Hug/rWz2n/
这是它在IE8中的样子:
http://f.cl.ly/items/0d1t3l2E1n1a3j0l1W2j/IE8.png
检查某些功能是否支持'madeUpAttribute' in element
在几种情况下对我来说是可以解决问题的。
实际上,您可以尝试检查元素的原型。
在较旧的IE中没有DOM对象的原型,但有一个有趣的古老功能。
if (element.prototype) {
return 'madeUpAttribute' in element.prototype
} else {
document.expando = false;
var hasProp = true;
try {
element.madeUpAttribute = element.madeUpAttribute;
} catch(e) {
hasProp = false;
}
document.expando = true;
return hasProp;
}
不过,这将适用于第一个作业。设置属性后,将认为它确实存在。
相关文章:
- 将setTimeout()包装器实现为Element.prototype中的方法
- 这个表达式在JavaScript中意味着什么:if(special_validations中的$(element).at
- 如何在element.select的结果中包含当前元素
- js表单验证中的docment.forms[“myForm”][“Element”].value命令
- 使用element.click()来模拟Javascript中的Button click
- 迭代器中的return element.parentNode
- IE8 中的 element.attributes 包含太多项目
- AngularJS:使用 element.bind('input') 访问自定义指令中的事件
- Angular、Ether Angular.element(“#n”) 或 $(“#n”) 中的有效 jq
- Element.prop('scrollHeight') 为 Angular.js 中的不同列表项返回相同的值
- 为什么脚本在评估同一脚本中的“element.checked”时会有所不同,作用于具有相同结构的不同表行
- Javascript - element.madeUpAttribute 与 IE8- 中的 element.getAt
- ExtJs 6.0-Ext.dom.Element.query()-属性中的多个值-正确的选择器
- 指令中的element.remove()将所有兄弟元素的parentelelement /Node设置为null
- 把AngularJS 2的Component当作element属性中的函数来使用
- 检查Element是否为选择中的最后一个元素
- AngularJS:观察指令中的element.html()
- 如何在Chrome Inspect Element中找到生成资源的源代码
- javascript中的createElement或CSS中的hide element
- 如何在使用element.all的量角器端到端测试中从javascript的承诺返回值