【问题标题】:What is the javascript command to change the table top row (heading) cell tags from td to <th class="filter">将表顶行(标题)单元格标记从 td 更改为 <th class="filter"> 的 javascript 命令是什么
【发布时间】:2020-09-02 17:28:18
【问题描述】:

我有一个动态创建表的函数,如下所示

function createDisplayTable(rn,cn)
{
for(var r=0;r<parseInt(rn,10);r++)
{
var x=displayTable.insertRow(r);
for(var c=0;c<parseInt(cn,10);c++)  
{
var y=  x.insertCell(c);
}
}
}

但是,为了使用 JQuery/bootstrap 模块,我需要将顶行(标题)单元格标签从 td 更改为 &lt;th class="filter"&gt; 将进行更改的 Javascript 代码是什么?

【问题讨论】:

标签: javascript html-table tags heading


【解决方案1】:
var temp3= displayTable.rows[0].outerHTML;
var temp= temp3.replace(/<td>/g,'<th class="filter">');
var temp1="</td>";
temp= temp.replace(/temp1/g,'</th>');
temp= temp.replace("<tr>","<thead><tr>");
temp= temp.replace("</tr>","</tr></thead><tbody>");
var temp2= displayTable.outerHTML;
temp2=temp2.replace(temp3,temp);
temp2=temp2.replace("<tbody>","");
displayTable.outerHTML=temp2;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 2020-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多