如何查找并用jQuery替换HTML实体? [英] How do I find and replace HTML entities with jQuery?
问题描述
我已经使用HTML表为Drupal网站构建了日历模板,并且让jQuery向每个空单元格添加了无文本"类:
I've constructed a calendar template for a Drupal site using an HTML table, and I've got jQuery to add a class 'no-text' to each empty cell:
$('table.calendar td:empty').addClass('no-text');
这很好,但是我的问题是CMS所见即所得编辑器自动将HTML实体
添加到空单元格中.因此,我试图事先查找并用真实"空间替换实体,但是jQuery无法找到它们:
This works well, but my problem is that the CMS WYSIWYG editor automatically adds the HTML entity
to empty cells. I've therefore attempted to find and replace the entities with a 'real' space beforehand, but jQuery fails to find them:
$('table.calendar td').each(function() {
var $this = $(this);
var t = $this.text();
$this.text(t.replace('[entity here]',''));
});
此代码段在替换普通字符串时效果很好,但是
似乎有所不同!
This snippet works fine when replacing a normal string, but the
seems to be something different!
所以我的问题是:jQuery如何用于搜索和替换HTML实体?
So my question is this: how can jQuery be used to search and replace HTML entities?
推荐答案
最简单的方法是
$this.text(t.replace('\u00a0',''));
其中\u00a0
是
这篇关于如何查找并用jQuery替换HTML实体?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!