用jquery删除所有html标签? [英] Strip all html tags with jquery?
本文介绍了用jquery删除所有html标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在jquery中删除所有html标签。像PHP中的strip_tags这样的函数
How to strip out all html tags in jquery. the function like strip_tags in PHP
例如:有以下内容:
<div id='test'>This is <b>bold</b> and this <div>is</div> <i>italic</i>.</div>
现在我要将其更改为< div id ='test' >这是粗体,这是斜体。< / div>
推荐答案
使用 .text()
:
$('#test').text($('#test').text());
我曾两次使用 .text()
因为使用 .html()
设置内容将导致小于和大于标志的字符串被错误地呈现:
I used .text()
twice because using .html()
to set the contents will cause strings with lesser-than and greater-than signs to be rendered incorrectly:
Hello <foo> // Set with .text()
Hello <foo> // Set with .html()
如果您使用 .html()
,然后< foo>
将成为标签。
If you used .html()
, then <foo>
would become a tag.
这篇关于用jquery删除所有html标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文