我想检查一个电子邮件地址是否等于3个不同数组中任何字符串的子字符串。不幸的是,我写的函数不断给出“无法识别的表达式”错误。
var search = 'info@example.com'
jQuery.each(array1, array2, array3, jQuery(function(index, value) {
jQuery.each(value, jQuery(function(key, cell) {
if (jQuery(search).indexOf(cell) !== -1)
console.log('Found email in ' + index, cell)
}))
}))
这会引发以下错误:
Uncaught Error: Syntax error, unrecognized expression: info\\@example\\.com
我错过了什么?
答案 0 :(得分:5)
首先,每个需要将三个数组包装为单个数组。第二个问题是在匿名函数之前使用jQuery
。第三个问题是将search
字符串包装在jQuery对象中(这是触发错误的字符串)。
已更新 - demo:
jQuery.each([array1, array2, array3], (function(index, value) {
jQuery.each(value, (function(key, cell) {
if (search.indexOf(cell) !== -1)
console.log('Found email in '+index, cell)
}))
}))