抱歉,我无法在谷歌中找到教程,因为我不知道关键字...
var currentURL=location.href;
var str = currentURL;
if(str == "http://web.com/blabla" || str == "http://web.com/bleble"){
window.location = "http://web.com/ban";
} else {
}
如何使 str == "http://web.com/blabla"|| str == "http://web.com/bleble"
要列出吗?所以如果我想再次输入一些网址,我只需将网址输入列表即可。可以给我代码或链接教程吗???
最佳答案
基本上,您需要将所有 URL 放入一个数组中,然后遍历该数组以检查每个项目。
var urls = ['http://web.com/','http://web.net/','http://web.org'];
var current_url = '...';
for (var i = 0; i < urls.length; i++){
if (current_url == urls[i]){
window.location = "http://web.com/ban";
break; // exit the loop since we have already found a match
}
}
break
命令将终止循环并停止在数组中搜索匹配的 URL。由于如果 任何 URL 匹配,则需要执行您要执行的操作,因此匹配足以停止搜索。
关于javascript - 如果语句有一个字符串和其他字符串(生成列表),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31368116/