如何使用jQuery删除HTML和特殊字符?

编程入门 行业动态 更新时间:2024-10-09 18:22:29
本文介绍了如何使用jQuery删除HTML和特殊字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

< p>< p>< p>< ; table border =0cellpadding =1cellspacing =0> < tbody>< tr valign =top>< td class =headlines>•< / td>< td class =headlines>< a href = target =_ top> SOME TEXT< / a>< / td>< / tr> < / tbody>< / table>

将链接文本封装到段落标签中的div或位置会很好。

有什么想法?

解决方案

这个答案发布后。

请参阅 @ TJ's answer 为新问题提供解决方案。

使用— gasp,shock horror — 香草JavaScript !

var $ headlines = $('。headlines'), headlineText = $ headlines.text(), replaceText = headlineText.replace /•/G, ''); $ headlines.text(replaceText);

或者稍微性感的语法: '$'$>'$'$'$'$'$'$'$'$'$'$''); });

So what I want to do is remove all of the HTML table tag elements, leaving the link tags alone.

<table border="0" cellpadding="1" cellspacing="0"> <tbody><tr valign="top"><td class="headlines">•</td><td class="headlines"><a href="" target="_top">SOME TEXT</a></td></tr> </tbody></table>

It would be nice to wrap the linked text into a div or place in a paragraph tag.

Any thoughts?

解决方案

The question was changed to ask something completely different after this answer was posted.

See @T.J.'s answer for a solution to the new question.

Do it with — gasp, shock horror — vanilla JavaScript!

var $headlines = $('.headlines'), headlineText = $headlines.text(), replaceText = headlineText.replace(/•/g, ''); $headlines.text(replaceText);

or, slightly sexier syntax:

$('.headlines').text(function (index, text) { return text.replace(/•/g, ''); });

更多推荐

如何使用jQuery删除HTML和特殊字符?

本文发布于:2023-11-27 18:41:10,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   特殊字符   jQuery   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!