我已经在我的应用程序中升级到 jQuery 1.10.2,但我的代码中出现错误(在 $.each
中)。
'invalid 'in' operand e' .
这个错误发生在升级 jQuery 之后。在“this._currentFilterbarValue
”中,有一个字符串值,我需要根据某些条件对其进行检查。
_CheckForSkipInput: function () {
var IsSkip = false;
if (this._currentFilterColumn.type == "String") {
var stringSkipInput = new Array(">", "<", "=", "!");
$.each(this._currentFilterbarValue, function (index, value) {
if (jQuery.inArray(value, stringSkipInput) != -1)
IsSkip = true;
});
}
return IsSkip;
},
最佳答案
您尝试的是遍历 this._currentFilterbarValue
(这是一个字符串)中的字符,因此 jQuery.each()
失败
The
$.each()
function can be used to iterate over any collection, whether it is an object or an array.
所以试试吧
var IsSkip = false;
if (this._currentFilterColumn.type == "String") {
var stringSkipInput = new Array(">", "<", "=", "!");
for (var i = 0; i < s.length; i++) {
if (jQuery.inArray(s[i], stringSkipInput) != -1) IsSkip = true;
}
}
return IsSkip;
},
另一种方法,
将字符串 this._currentFilterColumn
转换为 字符数组
,然后使用 $.each()
var arr = this._currentFilterColumn.split(""); //Converting a string to char array
$.each(arr, function (index, value) { //Now iterate the character array
if (jQuery.inArray(value, stringSkipInput) != -1) IsSkip = true;
});
关于javascript - 类型错误 : invalid 'in' operand e in jquery 1. 10.2v,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20512133/