Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
.search 方法可以只搜索一个字符串吗?或者有没有办法让一个 .search 命令一次搜索多个字符串?(顺便说一句,我尝试了以下代码:y.search("c", "b", "a"),其中 y 是文本框输入。)
y.search("c", "b", "a")
您不能使用多个参数,但可以使用带有 or 运算符 ( |) 的正则表达式,如下所示:
|
y.search(/c|b|a/);
此方法也适用于长度超过一个字符的字符:
y.search(/string1|string2|string3/);