![](/img/trans.png)
[英]jquery Error in IE8: 'Object' doesn't support this property or method
[英]jQuery - Object doesn't support this property or method in IE8
我在我的一個項目中實現了便簽功能,我發現了與瀏覽器兼容性相關的問題。 我的代碼在IE8中不起作用,但在其他瀏覽器中工作正常。
我得到的錯誤是:
Message: Object doesn't support this property or method
Line: 45
Char: 3
Code: 0
URI: http://dev.mesocial.co/orange_theme/js/sticky_note_func.js
這些是40到50之間的界限:
var moved = function(note) {
// added by rupesh
// alert(JSON.stringify(lastCreatedNoteId));
var passId = note.id
if(lastCreatedNoteIdForJs.indexOf(note.id) != -1)
passId = lastCreatedNoteId[note.id];
// till here ///////
$.post(SITE_URL+'/dashboard/create-sticky-note/act/moved/sticky_note_id/'+passId+'/pos_x/'+note.pos_x+'/pos_y/'+note.pos_y,
function(data) {
//alert(data);
});
任何有關問題的幫助都將非常感激。
IE8不支持.indexOf()
。 在Internet Explorer中,它首次引入了IE9。
由於您使用的是jQuery,因此可以使用$.inArray()
方法。
在你的情況下,像這樣的東西:
if($.inArray(note.id, lastCreatedNoteIdForJs) != -1)
支持沒有jQuery的舊版瀏覽器:
如果您想在舊版瀏覽器中使用.indexOf()
,則需要時使用自己的數組原型。 原型看起來像這樣:
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = 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 = 0;
if (arguments.length > 1) {
n = Number(arguments[1]);
if (n != n) { // shortcut for verifying if it's NaN
n = 0;
} else if (n != 0 && n != Infinity && n != -Infinity) {
n = (n > 0 || -1) * Math.floor(Math.abs(n));
}
}
if (n >= len) {
return -1;
}
var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
for (; k < len; k++) {
if (k in t && t[k] === searchElement) {
return k;
}
}
return -1;
}
}
以上示例摘自Array.prototype.indexOf
上的MDN文章 。
檢查此鏈接它可能會幫助您... IndexOf僅在某些瀏覽器中工作..
IE <9不支持數組的.indexOf方法。
jQuery有一個方法,允許您檢查元素是否在數組中。
if($.inArray(note.id, lastCreatedNoteIdForJs) !== -1) {
passId = lastCreatedNoteId[note.id];
}
您還可以將該方法添加到Array對象: 如何在JavaScript中為Internet Explorer瀏覽器修復Array indexOf()
if (!Array.prototype.indexOf) {
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.