admin管理员组文章数量:1415139
When I try to replace the string "1/2" with an HTML character with this line:
$(this).text(($(this).text().replace('1/2','½')));
it is instead replaced with ½
How can I escape the ampersand (&) in javascript.
When I try to replace the string "1/2" with an HTML character with this line:
$(this).text(($(this).text().replace('1/2','½')));
it is instead replaced with ½
How can I escape the ampersand (&) in javascript.
Share Improve this question edited Feb 27, 2011 at 15:52 Mike Samuel 121k30 gold badges227 silver badges254 bronze badges asked Feb 26, 2011 at 19:38 SaneefSaneef 8,9307 gold badges31 silver badges42 bronze badges2 Answers
Reset to default 4If you want to deal in HTML, then just deal in HTML:
$(this).html(($(this).html().replace('1/2','½')));
That said, the escaped JavaScript representation of the character is "\u00BD"
, it should be simpler to just use "½"
though.
Jquery.text() is used to insert & properly escape text. So It is normal that & bees &.
To acplish what you want to do use .html() instead of .text() in both occurences.
本文标签: Escaping ampersand in javascriptjqueryStack Overflow
版权声明:本文标题:Escaping ampersand in javascriptjquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745222742a2648470.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论