除了可读性之外,使用
str.indexOf("src")
还有
str.match(/src/)
我个人更喜欢 match
(和 regexp) ,但同事们似乎反其道而行之。我们想知道这有没有关系?
编辑:
我应该在一开始就说明,这是针对那些将执行部分纯字符串匹配(在类属性中为 JQuery 提取标识符)的函数,而不是使用通配符等进行完整的 regexp 搜索的函数。
class='redBorder DisablesGuiClass-2345-2d73-83hf-8293'
这就是两者的区别:
string.indexOf('DisablesGuiClass-');
还有
string.match(/DisablesGuiClass-/)