JQuery

1个成员

query 全文检索关键词高亮显示

发表于 2016-12-29 3347 次查看

query 全文检索关键词高亮显示
// 根据查询的关键字去页面中所有指定的元素中去
// 查找符合关键字内容的值,并将该值加了COLOR的属性以及加粗的属性
//
//id:需要查找的HTML元素名称
//key:GET上面查询关键字名称
//color:高亮的颜色
//b:是否加粗
//--------------------------------------
function differ_text(id,key,color,b)
{
        var text;
        text =location.search.substring(1);
        text = text.replace(/&/ig,",");
        text = text.replace(/=/ig,",");
        text = text.split(",");

        for(i=0;i<text.length;i++)
        {
                if(text == key && text[(i+1)] != undefined)
                {
                        text = decodeURI(text[(i+1)]);
                        text = text.replace(//ig,'');
                        text = text.replace(/'/ig,''');
                        text = text.replace(/"/ig,'"');
                        break;
                }
        }
        if(text == null || text == '' || text == undefined)
        {
                return false;
        }

        if(text.length > 0)
        {
                $(id+":only-child:contains('"+text+"')").each(function (i){

                var b = $(this).html();

                var text_a = text.fontcolor(color);

                text_a = b == true ? text_a.bold () :text_a;

                var re = eval('/'+text+'/i');
                $(this).html(b.replace(re,text_a));
                });
        }
}

发表回复
你还没有登录,请先登录注册