如果你曾经使用过JavaScript,你就会知道Internet Explorer没有为Array.prototype.indexOf()[包括Internet Explorer 8]实现ECMAScript函数。这不是一个大问题,因为您可以使用以下代码扩展页面上的功能。

Array.prototype.indexOf = function(obj, start) {
     for (var i = (start || 0), j = this.length; i < j; i++) {
         if (this[i] === obj) { return i; }
     }
     return -1;
}

我应该什么时候实现这个?

我是否应该用下面的检查将它包装在我的所有页面上,检查原型函数是否存在,如果不存在,继续扩展数组原型?

if (!Array.prototype.indexOf) {

    // Implement function here

}

或者做浏览器检查,如果是ie,就实现它?

//Pseudo-code

if (browser == IE Style Browser) {

     // Implement function here

}

和其他人一样,我需要在Internet Explorer 6和Internet Explorer 7上测试我的代码。现在Internet Explorer 8为开发人员提供了一些很棒的工具,我很乐意使用。我还想开始用Internet Explorer 8测试我的代码,因为它很快就会发布。

The question is: how to run Internet Explorer 6, Internet Explorer 7, and Internet Explorer 8 on the same machine. So far with Internet Explorer 6 and Internet Explorer 7 I've been using Multiple IE. But people have reported (see comments on the page linked in the previous sentence) issue with Internet Explorer 6 after installing Internet Explorer 8. Those errors are related to focus in form fields. Running Internet Explorer 7 wouldn't matter so much as Internet Explorer 8 can use the Internet Explorer 7 rendering engine, but we still need Internet Explorer 6.

如何在同一台机器上运行Internet Explorer 6、Internet Explorer 7和Internet Explorer 8 ?

我使用Firebug,并有一些语句像:

console.log("...");

在我的页面上。在IE8(可能是更早的版本),我得到脚本错误说“控制台”是未定义的。我试着把这个放在我页面的顶部:

<script type="text/javascript">
    if (!console) console = {log: function() {}};
</script>

我还是会得到错误。有办法消除错误吗?