我想搜索一個字符串到另一個字符串,但我面臨一個問題。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