这条或多或少神秘的线呢?
function check (a,b) {for (var i=0,k,f=1;k=b[i];i++) {f^=!!~a.indexOf(k)};return !f;}
或者,如果您愿意,可以使用Closure 编译版本
function check(d,e){for(var b=0,c,a=1;c=e[b];b++)a^=!!~d.indexOf(c);return!a};
输出
var x = "asdf";
console.log("found: %s", check (x,["qwer","rtz"])) //found: false
console.log("found: %s", check (x,["qwer","a"])) //found: true
这将检查是否a
包含包含在b
在你的情况下
check (window.location.href,["A","hh","eg3","1g4"])?/*Code to execute when true*/:/*When false*/
或者(function (a,b) {for (var i=0,k,f=1;k=b[i];i++) {f^=!!~a.indexOf(k)};return !f;})(window.location.href,["A","hh","eg3","1g4"])?alert("found"):alert("not found")