可能重複:
Fastest method to replace all instances of a character in a string爲什麼我的替換不工作按預期
我有這個
<p id="demo">/,\,:,*,?,",<,>,|</p>
<input type="button" onclick="myFunction()" value="Replace"/>
function myFunction() {
var str = document.getElementById("demo").innerHTML;
var n = str.replace(",", ", ");
document.getElementById("demo").innerHTML = n;
}
我要的是與此替換此"/,\,:,*,?,",<,>,|"
"/, \, :, *, ?, ", <, >, |"
但我得到的是這個"/, \,:,*,?,",<,>,|"
。
我在做什麼錯?
您找到答案在這裏:http://stackoverflow.com/questions/6064956/replace-all-occurrences-in-a-string –
或者在這裏:HTTP://計算器。 com/questions/2116558 /最快的方法來替換字符串中的所有實例 - 所以很顯然,關於相同問題的其他主題很多。 – w00