问题描述
- 怎样让table表格中的数据进行批量添加
-
就是利用一个按钮实现,批量添加,有没有主要的代码,看一下,就是jsp页面的就行了
解决方案
<script type="text/javascript">
var learnnum=0;
var learntemp=0;
function addlearn(){
var learntb = document.getElementById('learntb');
learnnum += 1;
learntemp += 1;
var learntr = document.createElement('tr');
learntr.id = "learntr"+learnnum;
var learntd1 = document.createElement('td');
learntd1.className = "td3";
learntd1.innerHTML = "起止时间:";
var learntd2 = document.createElement('td');
learntd2.className ="td4";
learntd2.innerHTML = "<input type='text' name='learntime"+ learnnum +"'/>";
var learntd3 = document.createElement('td');
learntd3.className = "td3";
learntd3.innerHTML = "毕业学校:";
var learntd4 = document.createElement('td');
learntd4.className ="td4";
learntd4.innerHTML = "<input type='text' name='endschool"+ learnnum +"'/>";
var learntd5 = document.createElement('td');
learntd5.className = "td3";
learntd5.innerHTML = "所学专业:";
var learntd6 = document.createElement('td');
learntd6.className ="td4";
learntd6.innerHTML = "<input type='text' name='professional"+ learnnum +"'/>";
var learntd7 = document.createElement('td');
learntd7.className = "td3";
learntd7.innerHTML = "教育方式:";
var learntd8 = document.createElement('td');
learntd8.className ="td4";
learntd8.innerHTML = "<input type='text' name='way"+ learnnum +"'/>";
learntr.appendChild(learntd1);
learntr.appendChild(learntd2);
learntr.appendChild(learntd3);
learntr.appendChild(learntd4);
learntr.appendChild(learntd5);
learntr.appendChild(learntd6);
learntr.appendChild(learntd7);
learntr.appendChild(learntd8);
learntb.appendChild(learntr);
// var lt = document.getElementById('learntemp');
// lt.value = learntemp;
}
</script>
<body onload="addlearn();">
This is my JSP page. <br>
<table>
<tbody id="learntb">
</tbody>
</table>
</body>
解决方案二:
声明一个数组,用push方法将每一串记录的对象加入数组中,将数组传给后台。
时间: 2024-12-27 14:39:32