插入的jquery HTML呈现为原始文本
我有奇怪的情况,我有那个字符串
lorem<br/><br/>ipsum<br/><br/>a<br/>b<br/><br/>c
这是一个div:
$('div.desc').html(that_string);
要么
$('div.desc').html($.parseHTML(that_string));
但在这两种情况下,它都被渲染为原始文本:
lorem
ipsum
a
b
c
代替
lorem ipsum a b c
为什么?
$('div.desc').html(decodeURI(that_string)); //OR $('div.desc').html($.parseHTML(decodeURI(that_string)));
decodeURI()
函数将解码字符串,以便输出<
, >
等。
你可以通过一点jQuery解析来欺骗它
$('div.desc').html( $('').html(that_string).text() );
小提琴