添加上标< sup>所有商标和注册商标符号周围的标签 [英] Adding superscript <sup> tags around all trademark and registered trademark symbols

查看:400
本文介绍了添加上标< sup>所有商标和注册商标符号周围的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在每个™,®,©周围添加< sup>< / sup> 标记。在我的页面中。

I am trying to add <sup></sup> tags around every ™, ®, © in my page.

我发现了这个问题: CSS上标注册商标帮助我入门。

I found this question: CSS superscript registration trademark which helped get me started.

该脚本的工作原理是将标签放置在适当的位置,但它在每个标签周围添加了两个< sup>< / sup> 标签而不是一个标签。

The script works in the sense that the tags are being placed in the proper locations, but it is adding two <sup></sup> tags around each instead of just one.

这是我的JS添加标签:

Here is my JS adding the tags:

jQuery("body").html(
    jQuery("body").html().replace(/&reg;/gi, '<sup>&reg;</sup>').replace(/®/gi, '<sup>&reg;</sup>').
        replace(/&trade;/gi, '<sup>&trade;</sup>').
        replace(/™/gi, '<sup>&trade;</sup>').
        replace(/&copy;/gi, '<sup>&copy;</sup>').
        replace(/©/gi, '<sup>&copy;</sup>')
);

如何确保每个符号只添加一次标记?某种条件可能?

How can I make sure the tags are only added once per symbol? A conditional of some sort maybe?

推荐答案

我没有重写整个标记(并删除所有绑定事件),而是去了对于类似的东西:

Instead of rewriting the entire markup (and removing all bound events), I'd go for something like that:

$('body :not(script)').contents().filter(function() {
    return this.nodeType === 3;
}).replaceWith(function() {
    return this.nodeValue.replace(/[™®©]/g, '<sup>$&</sup>');
});

DEMO: http://jsfiddle.net/QTfxC/

这篇关于添加上标&lt; sup&gt;所有商标和注册商标符号周围的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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