在java中,怎样实现点击一个添加按钮,下面的表单自动添加一行
2个回答
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
/*
*增加模板行
*/
function addRow() {
var table = document.getElementById("addTable");
var tbody = document.getElementById("templeteTBody");
var newTBody = tbody.cloneNode(true);
newTBody.style.display="";
var footTBody = document.getElementById("footTbody");
return table.insertBefore(newTBody,footTBody);
}
/*
*删除模板行
*/
function deleteRow(obj) {
var tbody = obj.parentNode.parentNode.parentNode;
var table = document.getElementById("addTable");
table.removeChild(tbody);
}
/**
*向模板中填充值
*/
function setValue(){
var tbody=addRow();
}
</script>
<BODY>
//页面代码
<input type="button" value="增加" onclick="setValue()">
<table id="addTable">
<tbody id="templeteTBody" style="display: none;">
<tr>
<td><input type="button" value="删除" onclick="deleteRow(this)"/></td>
<td>a</td>
<td><input type="text" /></td>
<td>b</td>
<td><input type="text" /></td>
</tr>
</tbody>
<tbody id="footTbody">
</tbody>
</table>
</BODY>
</HTML>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
/*
*增加模板行
*/
function addRow() {
var table = document.getElementById("addTable");
var tbody = document.getElementById("templeteTBody");
var newTBody = tbody.cloneNode(true);
newTBody.style.display="";
var footTBody = document.getElementById("footTbody");
return table.insertBefore(newTBody,footTBody);
}
/*
*删除模板行
*/
function deleteRow(obj) {
var tbody = obj.parentNode.parentNode.parentNode;
var table = document.getElementById("addTable");
table.removeChild(tbody);
}
/**
*向模板中填充值
*/
function setValue(){
var tbody=addRow();
}
</script>
<BODY>
//页面代码
<input type="button" value="增加" onclick="setValue()">
<table id="addTable">
<tbody id="templeteTBody" style="display: none;">
<tr>
<td><input type="button" value="删除" onclick="deleteRow(this)"/></td>
<td>a</td>
<td><input type="text" /></td>
<td>b</td>
<td><input type="text" /></td>
</tr>
</tbody>
<tbody id="footTbody">
</tbody>
</table>
</BODY>
</HTML>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询