一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

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

时间:2010-05-04 编辑:简简单单 来源:一聚教程网

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         {
                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));
                });
        }
}

热门栏目