开发者

How to inject html code using jquery? [duplicate]

This question already has answers here: How to put HTML in jQuery .text() (6 answers) Closed 8 years ago.

I have a tag that I want to inject some html code... ...the html code is like this...

line:1   3spaces b4<br /><br />line:3     5spaces

b4<br /> 5spaces b4, line: 4

If I use .text inj开发者_StackOverflow中文版ect this code, it just shows text, but not the html code. I would like to convert it to a html code, how can I do so?? Thank you.


Use .html() instead of .text()


Use .html() instead of .text().


Try:

$('#divname').html("code");


Solve it,

I need have a var htmlCode first, to convert it to decode HTML code, and use the html function... ... Thank everyone.

var htmlCode = $("<p/>").html("line:1   3spaces b4&lt;br /&gt;&lt;br /&gt;line:3     5spaces b4&lt;br /&gt;     5spaces b4, line: 4").text();

$("#aaa").html(htmlCode); 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜