javascript 使用 jquery 从字符串中删除 html 标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7540308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 00:27:28  来源:igfitidea点击:

Remove html tags from string using jquery

javascriptjquery

提问by josh

i want to know how to remove html tags from a string using jquery, html looks like this

我想知道如何使用 jquery 从字符串中删除 html 标签,html 看起来像这样

var string = '<p><marquee> some text </marquee>/p>';

now i want to remove all html tags and just want the plain text from it.

现在我想删除所有的 html 标签,只想要其中的纯文本。

thank you

谢谢

回答by NimChimpsky

jQuery text()will help you like this :

jQuery text()将帮助您像这样:

var willbeequaltosometext = $("marquee").text();

回答by georg87

You could do this yust like this:

你可以这样做:

$('<p><marquee> some text </marquee></p>').text()

回答by Shree

try:

尝试:

alert($('<li>Some text...</li>').text());