关键字高亮JS

        //高亮
        this.highlightKeys = searchData.content.split(' ');
        this.highlightLength = this.highlightKeys.length;
        this.highlights = [];
        this.highlightChilds($('tweetRegion').childNodes);
        this.highlightChilds($('searchTweetPageUserList').childNodes);
        $A(this.highlights).each(function(item) {
            var tag = document.createElement('span');
            item.tag.parentNode.replaceChild(tag, item.tag);
            tag.innerHTML = item.html;
        });



    highlightChilds: function(elements) {
        var length = elements.length;
        if (length == 0) return;
        var value = "";
        var i, j, exist;
        for (i = 0; i < length; i++) {
            if (elements[i].nodeType == 3) {
                value = elements[i].nodeValue.toString().trim();
                exist = false;
                if (value != "") {
                    for (j = 0; j < this.highlightLength; j++) {
                        if (value.indexOf(this.highlightKeys[j]) > -1) {
                            exist = true;
                            value = value.replace(this.highlightKeys[j], '<span style="color:#CA4004;">' + this.highlightKeys[j] + '</span>')
                        }
                    }
                    if (exist) {
                        this.highlights.push({ tag: elements[i], html: value });
                    }
                }
            }
            this.highlightChilds(elements[i].childNodes);
        }
    },
此条目发表在technologys分类目录,贴了标签。将固定链接加入收藏夹。