为防止.text跳过浏览器上的html标签? [英] Hot to prevent .text to escape the html tags on the browser?
本文介绍了为防止.text跳过浏览器上的html标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下代码显然会转义HTML标签并进行打印:
< p> Full Membership - 1 Year:< span> $ 25< ; / span>< / p>
在浏览器上而不是
完全会员 - 1年:$ 25
$(。ms_total ).text(< p>完全会员 - 1年:< span> $ 25< / span>< / p>);
如何防止这种情况发生?
解决方案
尝试 .html : -
$(。ms_total)。html(< p>完全会员 - 1年:< span> $ 25< / span>< / p>中);
正如官方网站所记载: - $ / b>
$ b
获取匹配
元素集中第一个元素的HTML内容,或设置每个匹配元素的HTML内容。
The following code apparently escapes the HTML tags and prints
<p>Full Membership - 1 Year:<span>$25</span></p>
on the Browser instead of
Full Membership - 1 Year:$25
$(".ms_total").text("<p>Full Membership - 1 Year:<span>$25</span></p>");
How do I prevent that?
解决方案
try .html :-
$(".ms_total").html("<p>Full Membership - 1 Year:<span>$25</span></p>");
As documented in official site :-
Get the HTML contents of the first element in the set of matched elements or set the HTML contents of every matched element.
这篇关于为防止.text跳过浏览器上的html标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文