需要替换特定单词的字体

我想将字体系列(Arial)更改为HTML文档中出现的单词“AAAAA”。 这个词可以来自DB多次,但我需要单独替换单个单词的字体。

我认为它将由JavaScript完成。 任何人都知道怎么做吗?

让我们说我们需要格鲁吉亚

  .geo{ font-family:Georgia; font-style:italic; font-weight:bold; font-size:19px; } 

演示

 var $els = $('body *'); // iterate through all elements // or define specific for performance. $els.each(function(){ $(this).html($(this).text().replace(/AAAAA/g, 'AAAAA')); }); 

如果可以给你带来问题(通常通过DOM使用)……我建议使用AAAAA

 $.fn.changeWord = function (str, className) { var regex = new RegExp(str, "gi"); return this.each(function () { this.innerHTML = this.innerHTML.replace(regex, function(matched) { return "" + matched + ""; }); }); }; 

叫它

 $('#myDiv').changeWord('specialWord', 'sw'); 

DEMO。

更新: DEMO。

          

Original Text

Hi.. testing test aaaa
rreee AAAA test

Original Text Replace ( global and case sensitive search in string )

Hi.. testing test aaaa
rreee AAAA test

Original Text Replace ( global and case insensitive search in string )

Hi.. testing test aaaa
rreee AAAA test