Bil*_*ull 38 javascript jquery
我收到一个错误,这是一个非法的继续声明.我有一个单词列表来检查表单验证,问题是它是否将一些子字符串与保留字匹配,所以我创建了另一个干净单词数组来匹配.如果匹配一个干净的单词,则如果匹配保留字,则继续其他,提醒用户
$.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;
}
});
});
Run Code Online (Sandbox Code Playgroud)
Jam*_*ice 84
该continue语句适用于普通的JavaScript循环,但jQuery each方法要求您使用该return语句.返回任何不是假的东西,它会表现为一个continue.返回false,它将表现为break:
$.each(cleanword,function(){
if ( resword == cleanword ){
return true;
}
else if ( filterName.toLowerCase().indexOf(this) != -1 ) {
//...your code...
}
});
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅jQuery文档.