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

我已经在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()启动qs.forEach()的行上

  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 }); 

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); } }; } 

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

我还必须在修复forEach()问题后将indexOf()添加到Array对象以使其正常工作

 if (!Array.prototype.indexOf) { Array.prototype.indexOf = function(elt) { var len = this.length >>> 0; var from = Number(arguments[1]) || 0; from = (from < 0) ? Math.ceil(from) : Math.floor(from); if (from < 0) from += len; for (; from < len; from++) { if (from in this && this[from] === elt) return from; } return -1; }; } 
    Interesting Posts