js动态添加tr表格

来源:互联网 发布:淘宝6.1.7版本下载官方 编辑:程序博客网 时间:2024/05/16 06:38

就是为了纪念一下自己用过的技术

var tbl = document.getElementById('tblSample'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; var row = tbl.insertRow(lastRow); // left cell var cellLeft = row.insertCell(0); var textNode = document.createTextNode(iteration); cellLeft.appendChild(textNode); // right cell var cellRight = row.insertCell(1); var el = document.createElement('input'); el.type = 'text'; el.name = 'txtRow' + iteration; el.id = 'txtRow' + iteration; el.size = 40; el.onkeypress = keyPressTest; cellRight.appendChild(el); // select cell var cellRightSel = row.insertCell(2); var sel = document.createElement('select'); sel.name = 'selRow' + iteration; sel.options[0] = new Option('text zero', 'value0'); sel.options[1] = new Option('text one', 'value1'); cellRightSel.appendChild(sel); } 


原创粉丝点击