如何使用text()函数插入html文本? [英] How to insert html text with text() function?
本文介绍了如何使用text()函数插入html文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要更改包含html的元素的内容.
I need to change the content of an element which includes html.
我尝试过此方法,但是html标签已打印
I tried with this, but the html tags are printed
$('#content-sections label').text('my text <span>a span element</span>');
按原样打印:
my text <span>a span element</span>
推荐答案
您必须使用 html()
一个>为此.例如:
You have to use html()
for this. For example:
$('#content-sections label').html('my text <span>a span element</span>');
哦,为了获得更好的性能,请改用此:
Oh, and for better performances, use this instead:
$('#content-sections').find('label').html('my text <span>a span element</span>');
这篇关于如何使用text()函数插入html文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文