我收到一条错误消息,指出其中包含非法的 continue 语句。 我有一个单词列表来检查表单验证,问题是它正在将一些子字符串与保留字匹配,所以我创建了另一个干净的单词数组来匹配。如果它匹配一个干净的字继续否则如果它匹配一个保留字提醒用户
$.each(resword,function(){
$.each(cleanword,function(){
if ( resword == cleanword ){
continue;
}
else if ( filterName.toLowerCase().indexOf(this) != -1 ) {
console.log("bad word");
filterElem.css('border','2px solid red');
window.alert("You can not include '" + this + "' in your Filter Name");
fail = true;
}
});
});
最佳答案
continue
语句适用于普通的 JavaScript 循环,但 jQuery each
方法要求您改用 return
语句。返回任何不为 false 的内容,它将表现为 continue
。返回 false,它将表现为 break
:
$.each(cleanword,function(){
if ( resword == cleanword ){
return true;
}
else if ( filterName.toLowerCase().indexOf(this) != -1 ) {
//...your code...
}
});
有关详细信息,请参阅 jQuery docs .
关于javascript - javascript $.each 循环中的非法 continue 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7028716/