css: .tuc { color:red; }
//模糊查询调用此方法即可
function mh_Search() {
$(".search_mh").keyup(function () {
var mh = $(this).val();
console.log(mh);
//每次恢复原样
$(".sInfo td b").replaceWith($(".sInfo td b").html());
if (mh.trim() != "" && mh != "undefined") {
setCss(mh);
} else {
clearSelection();
}
});
}
function setCss(searchText) {
clearSearch();//先清空
var regExp = new RegExp(searchText, 'g');//正则筛选;
$('.sInfo td').each(function ()//遍历获取;
{
var html = $(this).html();
var newHtml = html.replace(regExp, '<span class="tuc ">' + searchText + '</span>');//设置
$(this).html(newHtml);//替换;
});
}
//清除高亮显示效果
function clearSearch() {
$('.sInfo td').each(function ()//遍历
{
$(this).find('.tuc ').each(function ()//找到所有tuc属性的元素;
{
$(this).replaceWith($(this).html());//将他们的属性去掉;
});
});
}