jQuery:选择仅包含“& nbsp;"的段落 [英] JQuery: select paragraphs that only contain " "

查看:120
本文介绍了jQuery:选择仅包含“& nbsp;"的段落的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
删除仅带有& nbsp;的元素使用jQuery的空间​​

Possible Duplicate:
Remove elements with only a   space using jQuery

在后端进行换行时,WordPress会通过添加<p>&nbsp;</p>来实现此目的.

Wordpress does this thing with adding <p>&nbsp;</p> when doing a line-break in the backend.

我想知道是否可以通过jquery选择那些p.

I wonder if it is possible to select those p's somehow with jquery.

我猜empty()不起作用,因为它不是真的为空,但包含&nbsp;.但是contains()可能也不起作用,因为很多其他段落也包含空格,对吧?

I guess empty() wouldn't work since it isn't really empty but contains a &nbsp;. But contains() wouldn't probably work either since a lot of other paragraphs also contain a space, right?

我只想选择仅具有此 "的那些paragpah内部.

I only want to select those paragpahs that have only this " " inside.

更新

我应该提到我不想删除p,而是要向其中添加一个类.

I should have mentioned that I don't want to remove the ps but add a class to it.

推荐答案

如果可以访问主题文件,请将其添加到functions.php文件中.

Add this to your functions.php file if you have access to the theme files.

function user_content_replace($content) {
    return str_replace('<p>&nbsp;</p>','<p class="example">&nbsp;</p>',$content);
}
add_filter('the_content','user_content_replace', 99);

我让它插入一个类而不是删除它.

I made it insert a class instead of removing.

这篇关于jQuery:选择仅包含“&amp; nbsp;"的段落的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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