3
A
回答
7
根据ES5 compatability table,Array.prototype.lastIndexOf
在除IE8及以下版本以外的所有浏览器中均受支持。
如果您需要支持此类浏览器,可以使用可用的各种polyfills之一(或more complete ES5 polyfill solution)。
+0
你击败了我。 – HMR
1
某些浏览器(IE)不支持很多JavaScript属性。我通常在MDN找到一个解决方案:
https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/lastIndexOf
的代码有:
if (!Array.prototype.lastIndexOf)
{
Array.prototype.lastIndexOf = function(searchElement /*, fromIndex*/)
{
"use strict";
if (this == null)
throw new TypeError();
var t = Object(this);
var len = t.length >>> 0;
if (len === 0)
return -1;
var n = len;
if (arguments.length > 1)
{
n = Number(arguments[1]);
if (n != n)
n = 0;
else if (n != 0 && n != (1/0) && n != -(1/0))
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
var k = n >= 0
? Math.min(n, len - 1)
: len - Math.abs(n);
for (; k >= 0; k--)
{
if (k in t && t[k] === searchElement)
return k;
}
return -1;
};
}
0
lastIndexOf似乎只有在IE9/10中实现。您需要使用垫片来支持它。具体参见:ES5-shim,行509-535。
相关问题
- 1. AngularJS不会在Internet Explorer 8
- 2. Internet Explorer $ .ajax()不会加载
- 3. TinyMCE的在Internet Explorer不会加载
- 4. KineticJS不会加载在Internet Explorer
- 5. 按键事件不会在Internet Explorer
- 6. 平变化不会在是Internet Explorer
- 7. CSS:李悬停不会在Internet Explorer 6
- 8. 按钮不会在Internet Explorer中更新
- 9. 锚不会在Internet Explorer中工作11
- 10. 的Response.Redirect()将不会在Internet Explorer
- 11. 笨 - cookies不会在Internet Explorer 8
- 12. 图像高度不会在Internet Explorer 8
- 13. window.innerWidth不会与Internet Explorer的Windows Mobile
- 14. 会话变量不使用Internet Explorer 9
- 15. JavaScript的Internet Explorer不会检测window.closed
- 16. Internet Explorer不会显示Facelets文件
- 17. Internet Explorer不会呈现按钮悬停
- 18. Internet Explorer 8不会播放MIDI文件
- 19. PHP,会话Cookie和Internet Explorer
- 20. Internet Explorer删除会话
- 21. CSS不能在Internet Explorer
- 22. 在Internet Explorer 8
- 23. 在Internet Explorer
- 24. toSource在Internet Explorer
- 25. 在Internet Explorer
- 26. 在Internet Explorer
- 27. 在Internet Explorer
- 28. SC.oEmbed在Internet Explorer
- 29. 在Internet Explorer
- 30. 在Internet Explorer
根据W3School,lastIndexOf是由IE支持的:http://www.w3schools.com/jsref/jsref_lastindexof.asp – sdespont
@sdespont,不会是第一次w3schools错了 – epoch