ta-*_*run 3 javascript google-chrome-devtools
调试别人的代码,找到了,

如何if-in评价为真?但是仅在chrome中发生,IE评估为false
它进行评估,true因为fileInputDOM元素files在Chrome上具有属性.它是File API的一部分.它false在IE上,因为他们只在IE10中将IE添加到IE中.我猜你必须使用IE9或更早版本.
这就是in运算符的作用:检查对象是否具有给定名称的属性,无论是自己的属性还是从原型对象继承的属性.
这是一个直接的JavaScript示例:
var obj = {foo: 42};
console.log('foo' in obj); // true
console.log('bar' in obj); // false
Run Code Online (Sandbox Code Playgroud)
您会在功能检测中看到这种情况.例如,如果您想知道用户使用的浏览器是否支持使用元素上的placeholder属性input,那么您需要查找reflect属性:
if ('placeholder' in document.createElement('input')) {
// It supports the placeholder attribute
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
77 次 |
| 最近记录: |