How to add single quote in the variable in Javascript?

前端 未结 4 1101
深忆病人
深忆病人 2020-12-11 01:33

I have variable var str as following:

var str = ;

I would like to make it as below

4条回答
  •  青春惊慌失措
    2020-12-11 02:27

    Escape each single quote with a back-slash:

    var quote_str = '\';\''
    

    …or wrap the string in quotes of a different kind (i.e. double quotes), but be sure to escape the inner double quotes as to not unintentionally close the string:

    var quote_str = "';'"
    

提交回复
热议问题