字符串匹配
-
源码
/** * 判断字符串是否相等,目标字符串可以是多个字符串 * @param source 目标字符串 * @param target 要和目标字符串匹配的字符串, * 可以传入数组,也可以是已经 分割的字符串 ["a","b"],"a,b" * @param splitChar 默认使用分割","分割 */ function textEquel(source,target,splitChar,temp){ splitChar = splitChar||","; if(!target) return true; if(typeof target == "string") target = target.split(splitChar); while(temp = target.pop()){ if(temp == source) return true;} return false; }
-
demo
textEquel("a","b,c,a,e") //true textEquel("a",["b","c","a","e"]) //true textEquel("a","a") //true textEquel("a","b|c|a|e","|") //true
网友评论