Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 需要替换特定单词的字体_Javascript_Jquery_Css_Fonts_Font Family - Fatal编程技术网

Javascript 需要替换特定单词的字体

Javascript 需要替换特定单词的字体,javascript,jquery,css,fonts,font-family,Javascript,Jquery,Css,Fonts,Font Family,我想将字体系列(Arial)更改为HTML文档中的单词“AAAAA”。这个词可以从DB中多次出现,但我需要单独替换这个词的字体 我认为它将由JavaScript完成。有人知道怎么做吗 假设我们需要格鲁吉亚 .geo{ font-family:Georgia; font-style:italic; font-weight:bold; font-size:19px; } var$els=$('body*');//遍历所有元素//或定义特定的性能。 $els.

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


我认为它将由JavaScript完成。有人知道怎么做吗

假设我们需要格鲁吉亚

  .geo{
    font-family:Georgia;
    font-style:italic;
    font-weight:bold;
    font-size:19px;
  }
var$els=$('body*');//遍历所有元素//或定义特定的性能。
$els.each(函数(){
$(this.html($(this.text().replace(/AAAAA/g,'aaaaaaa'));
});
如果
会给您带来问题(通常通过DOM使用)。。。我建议使用
aaaaaaa

更新:


$(文档).ready(函数(){
//$('body').replaceWith($('').append($(body.clone()).html().replace(/AAAA/g,'AAAA');
//或
//字符串中的全局和区分大小写搜索
$('#replaceTest2').replaceWith($('').append($('#replaceTest2').clone()).html().replace(/AAAA/g,'AAAA'));
//字符串中的全局搜索和不区分大小写的搜索
$('#replaceTest3').replaceWith($('').append($('#replaceTest3').clone()).html().replace(/AAAA/gi,'AAAA'));
});
身体
{
字体系列:巴塘;
字体:斜体;
字体大小:粗体;
}
原文
嗨..测试aaaa
雷伊AAAA
测试
原始文本替换(字符串中的全局和区分大小写搜索)
嗨..测试aaaa
雷伊AAAA
测试
原始文本替换(字符串中的全局搜索和不区分大小写的搜索)
嗨..测试aaaa
雷伊AAAA
测试

给该元素一个单独的Id,然后更改字体。可能是重复的&yesp。为了澄清,找到单词,将其放入一个新元素,并将Id分配给该元素。或者,给该元素一个所需的
样式。fontFamily
。我们有一些CMS页面,该单词也将以这种方式出现。任何用户都可以使用更多网站上的ts也需要更改字体。@Sankar,如果你查看链接的问题,它将向你展示如何识别一个单词,并在客户端用span标记将其包围。然后你可以通过应用css类元素来更改fontfamily、颜色和做你想做的每种样式。它正在工作,但有一些问题。tr with the below code specialWord google.com/specialWord“>specialWord​我在JQuery-1.7.1.Heera中遇到了相同的问题,该问题尚未解决。请检查下面链接的源代码。它也会替换链接中的内容。您正在尝试更改链接文本,但这不是您的问题,因此答案取决于您的问题。
var $els = $('body *'); // iterate through all elements // or define specific for performance.

$els.each(function(){ 
  $(this).html($(this).text().replace(/AAAAA/g, '<span class="geo">AAAAA</span>')); 
});
$.fn.changeWord = function (str, className) {
    var regex = new RegExp(str, "gi");
    return this.each(function () {
        this.innerHTML = this.innerHTML.replace(regex, function(matched) {
            return "<span class='" + className + "'>" + matched + "</span>";
        });
    });
};
$('#myDiv').changeWord('specialWord', 'sw');
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script src="Scripts/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //$('body').replaceWith( $('<div></div>').append($(body).clone()).html().replace(/AAAA/g, '<span style="font-family: Arial; color:red;">AAAA</span>');


            //Or


            // global and case sensitive search in string
            $('#replaceTest2').replaceWith($('<div></div>').append($('#replaceTest2').clone()).html().replace(/AAAA/g, '<span style="font-family: Arial; color:red;">AAAA</span>'));
            // global and case insensitive search in string
            $('#replaceTest3').replaceWith($('<div></div>').append($('#replaceTest3').clone()).html().replace(/AAAA/gi, '<span style="font-family: Arial; color:red;">AAAA</span>'));
        });
    </script>
    <style type="text/css">
        body
        {
            font-family: Batang;
            font-style: italic;
            font-weight: bolder;
        }
    </style>
</head>
<body>
    <h1>
        Original Text
    </h1>
    <div id="replaceTest1">
        Hi.. testing <span style="font-family: Ebrima;">test aaaa</span>
        <div>
            <span style="font-family: Bookshelf Symbol 7; font-style: normal;">rreee AAAA </span>
            test
        </div>
    </div>
    <h1>
        Original Text Replace ( global and case sensitive search in string )
    </h1>
    <div id="replaceTest2">
        Hi.. testing <span style="font-family: Ebrima;">test aaaa</span>
        <div>
            <span style="font-family: Bookshelf Symbol 7; font-style: normal;">rreee AAAA </span>
            test
        </div>
    </div>
    <h1>
        Original Text Replace ( global and case insensitive search in string )
    </h1>
    <div id="replaceTest3">
        Hi.. testing <span style="font-family: Ebrima;">test aaaa</span>
        <div>
            <span style="font-family: Bookshelf Symbol 7; font-style: normal;">rreee AAAA </span>
            test
        </div>
    </div>
</body>
</html>