I have a CMS (Joomla) site, with the ®
sign on many places. Instead of going through every module and adding a span
to it, than making it superscript
, is there a JS or jQuery code I can use, to pick this sign up and make it superscript?
我有一个CMS(Joomla)网站,在许多地方都有®标志。而不是通过每个模块并添加一个跨度,而不是使其成为上标,是否有我可以使用的JS或jQuery代码,选择这个注册并使其成为上标?
I know it is a long shot, but if that actually exists it would be super cool.
我知道这是一个很长的镜头,但如果真的存在,那将是非常酷的。
Thanks.
EDIT: If possible with pure JS as I have a complex slider and including jQuery brings errors
编辑:如果可能使用纯JS,因为我有一个复杂的滑块,包括jQuery带来错误
2 个解决方案
#1
1
You can actually do this using JavaScript / jQuery, but it is a very costly function!
你可以使用JavaScript / jQuery实际做到这一点,但它是一个非常昂贵的功能!
$(document).ready(function () {
$("body").html($("body").html().replace(new RegExp('®', 'g'), '<sup>®</sup>'));
});
Note 1: This is terrible in performance!
注1:这在性能上很糟糕!
Note 2: This may remove the
events
, so better replace"body"
with a selector, that has only Rich Text Content!注意2:这可能会删除事件,因此最好将“body”替换为仅包含Rich Text Content的选择器!
Solution for Note 2:
注2的解决方案:
$(document).ready(function () {
$(".user-content-area").html($(".user-content-area").html().replace(new RegExp('®', 'g'), '<sup>®</sup>'));
});
There may be chances like using ®
for the same. So, for those:
有可能使用®对于相同的。所以,对于那些:
$(document).ready(function () {
$(".user-content-area").html($(".user-content-area").html().replace(new RegExp('®', 'gi'), '<sup>®</sup>'));
});
There's an alternative version for the regex! You can use split()
and join()
too! Instead of:
还有正则表达式的替代版本!你也可以使用split()和join()!代替:
.replace(new RegExp('®', 'g'), '<sup>®</sup>')
Change it with:
改变它:
.split('®').join('<sup>®</sup>')
.split('®').join('<sup>®</sup>')
Note: This is case sensitive!
:(
注意:这是区分大小写的! :(
#2
1
Better use some CSS instead of some javascript for that. CSS:
更好地使用一些CSS而不是一些javascript。 CSS:
.sup { vertical-align: super; }
HTML:
<span class="sup">®</span>
You could easily do a search/replace on many files using Sed
您可以使用Sed轻松地对许多文件进行搜索/替换
find . -name "*.php" -print | xargs sed -i 's/\®/<span class=\"sup\">\®<\/span>/g'
(note: not tested!)
(注意:未经测试!)
#1
1
You can actually do this using JavaScript / jQuery, but it is a very costly function!
你可以使用JavaScript / jQuery实际做到这一点,但它是一个非常昂贵的功能!
$(document).ready(function () {
$("body").html($("body").html().replace(new RegExp('®', 'g'), '<sup>®</sup>'));
});
Note 1: This is terrible in performance!
注1:这在性能上很糟糕!
Note 2: This may remove the
events
, so better replace"body"
with a selector, that has only Rich Text Content!注意2:这可能会删除事件,因此最好将“body”替换为仅包含Rich Text Content的选择器!
Solution for Note 2:
注2的解决方案:
$(document).ready(function () {
$(".user-content-area").html($(".user-content-area").html().replace(new RegExp('®', 'g'), '<sup>®</sup>'));
});
There may be chances like using ®
for the same. So, for those:
有可能使用®对于相同的。所以,对于那些:
$(document).ready(function () {
$(".user-content-area").html($(".user-content-area").html().replace(new RegExp('®', 'gi'), '<sup>®</sup>'));
});
There's an alternative version for the regex! You can use split()
and join()
too! Instead of:
还有正则表达式的替代版本!你也可以使用split()和join()!代替:
.replace(new RegExp('®', 'g'), '<sup>®</sup>')
Change it with:
改变它:
.split('®').join('<sup>®</sup>')
.split('®').join('<sup>®</sup>')
Note: This is case sensitive!
:(
注意:这是区分大小写的! :(
#2
1
Better use some CSS instead of some javascript for that. CSS:
更好地使用一些CSS而不是一些javascript。 CSS:
.sup { vertical-align: super; }
HTML:
<span class="sup">®</span>
You could easily do a search/replace on many files using Sed
您可以使用Sed轻松地对许多文件进行搜索/替换
find . -name "*.php" -print | xargs sed -i 's/\®/<span class=\"sup\">\®<\/span>/g'
(note: not tested!)
(注意:未经测试!)