js中动态生成表格
function createTable() {
var t = document.getElementById("myT");
for ( var i = 0; i < 3; i++) {
var r = t.insertRow();
for ( var j = 0; j < 2; j++) {
var c = r.insertCell();
if (j == 0) {
c.innerHTML = "姓名:"+i+","+j;
} else {
c.innerHTML = "<input type='text' name='n' />";
}
}
}
t.setAttribute('border', '1');
}
function deleteTable() {
var objTable = document.getElementById("myT");
objTable.setAttribute('border', '0');
for ( var i = 0; i <= objTable.rows.length+1; i++) {
objTable.deleteRow(0);
}
}
jsp中的表单引发事件
<input type="button" onclick="createTable()" name="ty" value="试题类型" />
<input type="button" onclick="deleteTable()" name="re" value="清除表格" />
<table id="myT">
</table>