日期:2014-05-16  浏览次数:20324 次

js动态增加 删除行

添加页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<script language="javascript" type="text/javascript">???
???var nation_index = 0;
???var oTR = new Array();
???function addNation(){
????nation_index = nation_index+1;
????//var oTR = document.createElement("tr");
????oTR[nation_index] = document.createElement("tr");
????oTR[nation_index].className = "TableContent";
????var oTD = document.createElement("td");
????oTD.width=""
????oTD.align="center";
????oTD.innerHTML = "<input type=\"text\" id=\"level_id"+nation_index+"\" name=\"level\"? value=\""+nation_index+"\" onkeyup=\"valid(this);\">";????
????oTR[nation_index].appendChild(oTD);
?????? oTD = document.createElement("td");
?????? oTD.align="center";
????oTD.innerHTML = "<input type=\"text\" id=\"start_id"+nation_index+"\" name=\"start\"? value=\"\" onkeyup=\"valid(this);\">";
????oTR[nation_index].appendChild(oTD);
????oTD = document.createElement("td");
????oTD.align="center";
????oTD.innerHTML = "<input type=\"text\" id=\"end_id"+nation_index+"\" name=\"end\"?? value=\"\" onkeyup=\"valid(this);\">";
????oTR[nation_index].appendChild(oTD);
????oTD = document.createElement("td");
????oTD.align="center";
????oTD.innerHTML = "<input type=\"text\" id=\"rate_id"+nation_index+"\" name=\"rate\"? value=\"\" onkeyup=\"valid(this);count("+nation_index+");\">";
????oTR[nation_index].appendChild(oTD);
????oTD = document.createElement("td");
????oTD.align="center";
????oTD.innerHTML = "<input type=\"text\" id=\"number_id"+nation_index+"\" name=\"number\"? readonly=\"true\" value=\"\">"+"<a href=\"#here\" onclick=\"delNation("+nation_index+");\">删除</a>";
????oTR[nation_index].appendChild(oTD);
????table1.appendChild(oTR[nation_index]);
????
???}
???function delNation(theNO){
????table1.removeChild(oTR[theNO]);
????oTR[theNO] = null;
????nation_index = nation_index -1;
???
???}??????
???
???function valid(num){
???if(isNaN(num.value)){
??????????? ???alert("格式不对,应该是数字");
??????????? ???num.focus();
??????? ???? ??return false;
??????? ?}
???if(num.value>1000000000000||num.value<0){
??????????? ???alert("格式不对,应该是0—1000000000000的数字");
??????????? ???num.focus();
??????????? ???return false;
??????? ??}
???}
??</script>
</head>
<body>
<form name="personalTaxForm" method="post" action="">

<table width="99%" border="0" cellspacing="1" cellpadding="0"
?class="ReportTable" align="center">
?<tr class="ButtonTableContent">
??<td align="left"><input name="add" type="button" id="add"
???value="增 加" onClick="addNation()"></td>
?</tr>
</table>
<table class="ReportTable" width="99%" border="0" cellspacing="1"
?cellpadding="0" align="center">
?<tr class="TableContent" style="display:">
??<td class="TableListHeaderTd" width="20%" align="center">级数</td>
??<td class="TableListHeaderTd" width="20%" align="center">最小金额</td>
??<td class="TableListHeaderTd" width="20%" align="center">最大金额</td>
??<td class="TableListHeaderTd" width="20%" align="center">税率</td>
??<td class="TableListHeaderTd" width="20%" align="center">速算扣除数</td>
?</tr>
?<tbody id="table1"></tbody>
</table>
<script language="javascript" type="text/javascript">
????fb = ['cancel'];
????tb = ['返 回'];
????changeButtonName(fb,tb);
???</script></form>
</body>
</html>

编辑页面:

?

<%
String rownumber = (String)request.getAttribute("rownumber");
%>
<html>
<head>
<title>修改个税参数</title>
<script language="javascript" sr