jQuery插入的HTML呈现为原始文本 [英] jquery inserted HTML is rendered as a raw text

查看:73
本文介绍了jQuery插入的HTML呈现为原始文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况很奇怪,我有那个字符串

I have weird situation, I have that string

lorem<br/><br/>ipsum<br/><br/>a<br/>b<br/><br/>c

放置在div中的

$('div.desc').html(that_string);

$('div.desc').html($.parseHTML(that_string));

,但在两种情况下都将其呈现为原始文本:

but in both cases it is being rendered as a raw text:

lorem<br/><br/>ipsum<br/><br/>a<br/>b<br/><br/>c

代替

lorem

ipsum

a
b

c

为什么?

推荐答案

$('div.desc').html(decodeURI(that_string));
//OR
$('div.desc').html($.parseHTML(decodeURI(that_string)));

decodeURI()函数将解码字符串,以便输出<>等.

The decodeURI() function will decode the string so it will output <, > etc.

这篇关于jQuery插入的HTML呈现为原始文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆