关键字高亮显示
作者:互联网
var flag1 = $("#keyword").val() != undefined; var flag2 = $("#keyword").val() != null; var flag3 = $("#keyword").val() != ''; if ( flag1&&flag2&&flag3) { var keyword=$("#keyword").val(); var reg = new RegExp(txtReportName, 'ig'); var tableId = document.getElementById("table"); if (keyword!= null) { for (var i = 1; i < tableId.rows.length; i++) { for (var j = 1; j < tableId.rows[i].cells.length; j++) { var bb = tableId.rows[i].cells[j].innerHTML; console.log(bb); var displayColor = '<span style="color:#4e55ff">' + keyword+ '</span>'; var cc = bb.replace(reg, displayColor); tableId.rows[i].cells[j].innerHTML = cc; } } } }
完
标签:显示,rows,高亮,val,keyword,bb,关键字,tableId,var 来源: https://www.cnblogs.com/liouzeshuen/p/10539704.html