Representing single and double quotation marks in a string literal

后端 未结 2 1162
夕颜
夕颜 2020-12-22 11:17

I want to represent height in this format in javascript

6\'00\"

I tried this

var height = \'6\'+\"\'\"+\'00\"\';

which work

相关标签:
2条回答
  • 2020-12-22 12:03

    If you surround your text with single quotes, you need to escape the inner single quote, or if you surround your text with double quotes, you need to escape the inner double quote. Here are the two flavors:

    var height = '6\'00"';
    

    Or

    var height = "6'00\"";
    

    You could also use an HTML encoded version if you'd like:

    var height = '6'00"';
    

    (JSFiddle Example)

    0 讨论(0)
  • 2020-12-22 12:05

    Escape one or the other:

    "6'00\""
    '6\'00"'
    
    0 讨论(0)
提交回复
热议问题