将字体awsome图标添加到Javascript字符串

时间:2016-10-24 09:08:53

标签: javascript jquery string twitter-bootstrap icons

我有这个不断更改网页标题的脚本。

<script>
        var titleArray = ["AAAAA","BBBBB","CCCCC","DDDDD","EEEEE","FFFFF","GGGGG","HHHHH","IIIII","JJJJJ"];
        var N = titleArray.length;
        var i = 0;
        setInterval(func,500);
        function func(){
            if (i == 10) {
                i = 0;
            }
            document.title = titleArray[i];
            i++;
        }

</script>

标题是字符串形式但我想能够添加字体图标,如谷歌图标,字体真棒图标,bootstrap glypicons或icomoon等。我该怎么做?

1 个答案:

答案 0 :(得分:0)

如果我没有弄错你的问题,请尝试以下。

<html>
    <head>
        <link id="ico" rel="shortcut icon" type="image/x-icon" href="favicon.ico" />
        <script type="text/javascript">
            var titleArray = ["http://cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico","https://en.wikipedia.org/static/favicon/wikipedia.ico"];
            setInterval(func,500);
            var i=0;
            function func(){
                if (i == 2) {
                    i = 0;
                }
                document.getElementById('ico').href = titleArray[i];
                console.log(titleArray[i]);
                i++;
            }
        </script>
    </head>
    <body>
        <script type="text/javascript">
            func();
        </script>
    </body>
</html>