0
如何使用javascript或jQuery替換此字符\\
by \
?我嘗試這樣做:替換字符串中的特定字符
var string = "ABC\\testUserName"
var newString = string.replace("\\", "\")
我得到這個錯誤:
Uncaught SyntaxError: Unexpected token ILLEGAL
如何使用javascript或jQuery替換此字符\\
by \
?我嘗試這樣做:替換字符串中的特定字符
var string = "ABC\\testUserName"
var newString = string.replace("\\", "\")
我得到這個錯誤:
Uncaught SyntaxError: Unexpected token ILLEGAL
的\
是轉義字符,所以你需要將它們在你的replace()
呼籲加倍他們被視爲一個實例。試試這個:
var string = "ABC\\testUserName"
var newString = string.replace("\\\\", "\\");
console.log(newString);
感謝它的作品! –