我想搜索一个字符串到另一个字符串,但我面临一个问题。javascript搜索字符串包含'+'
有我的代码:
reference = "project/+bug/1234";
str = "+bug/1234";
alert(reference.search(str));
//it should alert 8 (index of matched strings)
但它警告-1:所以,STR没有被发现到参考。
我发现有什么问题,这似乎是“+”字为海峡,因为.search(“字符串+ STR”)似乎与正规表达式“+”
而不是使用reference.search(STR); use reference.indexOf(str); – Swapnil