JQuery的:追加HTML字符串为html [英] JQuery: append html string as html

查看:670
本文介绍了JQuery的:追加HTML字符串为html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想追加此字符串:

<div> hello </div>

作为HTML节点,但不是HTML,它只是附加文本

as an html node but instead of html it just appends the text

<div> hello </div>

如何使JQuery的追加这是一个HTML节点,而不仅仅是文字?

How do I make JQuery append this as an html node, not just text?

编辑:我想这两个嵌套的div和文字工作的解决方案,如果可能的话

I'd like a solution that works for both for nested divs AND text, if possible

推荐答案

编辑:添加交代...

Adding explaination...

// This is your string :)
var myString = "&lt;div&gt; hello &lt;/div&gt;";

// This is a way to "htmlDecode" your string... see link below for details.    
myString = $("<div />").html(myString).text();

// This is appending the html code to your div (which you don't have an ID for :P)
$("#TheDivIWantToChange").append(myString);

使用Javascript / jQuery文档编码

这篇关于JQuery的:追加HTML字符串为html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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