最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to give ID for TableRow using insertRow()? - Stack Overflow

programmeradmin0浏览0评论
 var table = document.getElementById("table1");
    var tr = table.insertRow();
    var td = tr.insertCell();
    td.innerHTML= document.getElementById('txt1').value;

i am using code like this. how to give Id for tr(TableRow). help me.

 var table = document.getElementById("table1");
    var tr = table.insertRow();
    var td = tr.insertCell();
    td.innerHTML= document.getElementById('txt1').value;

i am using code like this. how to give Id for tr(TableRow). help me.

Share Improve this question asked Aug 23, 2011 at 12:16 AravinthAravinth 1391 gold badge1 silver badge8 bronze badges
Add a comment  | 

4 Answers 4

Reset to default 18

Just give tr.id = "some_id". This will work.

because you use standard Javascript you have to use the function setAttribute("align", "center", 0);.

Try following:

tr.setAttribute("id", "myIdNameforThisRow", 0);
var table = document.getElementById("table1");
var tr = table.insertRow();
tr.id = 'id_for_this_row'; // Just assign a value to the new row's 'id' attribute
var td = tr.insertCell();
td.innerHTML= document.getElementById('txt1').value; 

create a variable first like var id=0;

then

tr.id=id;
id++;

use this code

发布评论

评论列表(0)

  1. 暂无评论