2012-07-05 146 views

回答

25

試試這個:

text = text.toString().replace(/"/g, '\\"') 

或者這樣:

text = text.toString().replace('"', '\\"') 
+0

@ badc0re在jsFiddle上查看演示:http://jsfiddle.net/antyrat/HzfZQ/ – antyrat 2012-07-05 15:02:29

1

這將做到:

text = text.toString().replace("\"", '\\\"'); 

你基本上由\