如何让jquery.couch.app.js与IE8一起使用

5 javascript jquery internet-explorer couchapp

我已经在IE7和IE8(在所有兼容模式下)的Windows XP SP3和IE8中的Windows 7旗舰版(在所有兼容模式下)中测试了这一点,并且它在两者上都以相同的方式失败.我正在运行couchapp存储库中的最新HEAD .这在我的OSX 10.6.3开发机器上工作正常.我在Windows 7旗舰版上测试了Chrome 4.1.249.1064(45376)和Firefox 3.6,它们都运行良好.与OSX 10.6.3上的Safari 4和Firefox 3.6一样

这是错误消息

网页错误详情

用户代理:Mozilla/4.0(兼容; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0)时间戳: 2010年4月28日星期三03:32:55 UTC

消息:对象不支持此属性或方法行:159字符:7代码:0 URI:http://192.168.0.105: 5984/test/_design/test/vendor/couchapp/jquery.couch.app.js

这是一个"冒犯"的代码,可以在Chrome,Firefox和Safari上使用.如果说失败在qs.forEach()从文件jquery.couch.app.js开始的行上

  157 var qs = document.location.search.replace(/^\?/,'').split('&');
  158 var q = {};
  159 qs.forEach(function(param) {
  160   var ps = param.split('=');
  161   var k = decodeURIComponent(ps[0]);
  162   var v = decodeURIComponent(ps[1]);
  163    if (["startkey", "endkey", "key"].indexOf(k) != -1) {
  164     q[k] = JSON.parse(v);
  165   } else {
  166    q[k] = v;
  167   }
  168 });
Run Code Online (Sandbox Code Playgroud)

edw*_*win 6

forEach()是最近添加到JavaScript规范的函数,因此并非所有浏览器都支持它.

您可以在MDC上阅读它:https: //developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array/forEach

在"兼容性"下,您会找到一个使forEach()可用的代码段.

if (!Array.prototype.forEach)
{
  Array.prototype.forEach = function(fun /*, thisp*/)
  {
    var len = this.length >>> 0;
    if (typeof fun != "function")
      throw new TypeError();

    var thisp = arguments[1];
    for (var i = 0; i < len; i++)
    {
      if (i in this)
        fun.call(thisp, this[i], i, this);
    }
  };
}
Run Code Online (Sandbox Code Playgroud)

因此,将上面的代码复制并粘贴到脚本中,forEach()应该可以正常工作.