添加上标< sup>所有商标和注册商标符号周围的标签 [英] Adding superscript <sup> tags around all trademark and registered trademark symbols
问题描述
我正在尝试在每个™,®,©周围添加< 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(/®/gi, '<sup>®</sup>').replace(/®/gi, '<sup>®</sup>').
replace(/™/gi, '<sup>™</sup>').
replace(/™/gi, '<sup>™</sup>').
replace(/©/gi, '<sup>©</sup>').
replace(/©/gi, '<sup>©</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/
这篇关于添加上标< sup>所有商标和注册商标符号周围的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!