如何使用jQuery删除HTML和特殊字符? [英] How do I remove HTML and special charaters using jQuery?

查看:75
本文介绍了如何使用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);

或者稍微性感的语法:

<$ p $($。'$'$>'$'$>'$'$'$'$'$'$'$'$'$'$'');
});


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 horrorvanilla 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和特殊字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆