How do I properly escape quotes inside HTML attributes?

前端 未结 6 875
遇见更好的自我
遇见更好的自我 2020-11-22 08:31

I have a drop down on a web page which is breaking when the value string contains a quote.

The value is \"asd, but in the DOM it always appears as an em

6条回答
  •  太阳男子
    2020-11-22 09:09

    " is the correct way, the third of your tests:

    
    

    You can see this working below, or on jsFiddle.

    alert($("option")[0].value);
    
    

    Alternatively, you can delimit the attribute value with single quotes:

    
    

提交回复
热议问题