如何正确地转义html属性内的引号? [英] How to properly escape quotes inside html attributes?
本文介绍了如何正确地转义html属性内的引号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
该值为asd
,但在DOM中总是显示为空字符串。
我已经尝试过我所知道的任何方式来正确地转义字符串,但无效。 / p>
< option value =asd> test< / option>
< option value =\asd> test< / option>
< option value =& quot; asd> test< / option>
< ; option value =&#34; asd> test< / option>
如何在页面上呈现这些信息,以便回传邮件包含正确的值?
解决方案
& quot ;
是正确的方式,您的三分之一的测试:
< option value =& ;asd> test< / option>
你可以看到这个工作在一个jsFiddle示例此处,或者,您可以使用单引号对属性值进行分隔:
< option value ='asd'> test< / option>
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 always appears as an empty string.
I have tried every way I know to escape the string properly but to no avail.
<option value=""asd">test</option>
<option value="\"asd">test</option>
<option value=""asd">test</option>
<option value=""asd">test</option>
Any idea how to render this on the page so the postback message contains the correct value?
解决方案
"
is the correct way, the third of your tests:
<option value=""asd">test</option>
You can see this working in a jsFiddle example here. Alternatively, you can delimit the attribute value with single quotes:
<option value='"asd'>test</option>
这篇关于如何正确地转义html属性内的引号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文