How do I add slashes to a string in Javascript?

后端 未结 8 1788
陌清茗
陌清茗 2020-12-29 19:05

Just a string. Add \\\' to it every time there is a single quote.

8条回答
  •  别那么骄傲
    2020-12-29 19:43

    To be sure, you need to not only replace the single quotes, but as well the already escaped ones:

    "first ' and \' second".replace(/'|\\'/g, "\\'")
    

提交回复
热议问题