[英]jQuery check if email address part of string in array elements
我想檢查電子郵件地址是否等於或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
我想念什么?
首先發行每個需要將三個數組包裝為單個數組。 第二個問題是在匿名函數之前使用jQuery
。 第三個問題是將search
字符串包裝在jQuery對象中(這是觸發錯誤的對象)。
更新- 演示 :
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)
}))
}))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.