基本代码已写出来了,直接可以用调试。求助。动态增加一行数据,如果点击“复制”按钮,就把该行数据内容填写到新增的那行数据里。如果点“增加一行”则新增一行空白数据。
基本代码已经弄出来了,求调试
‘’求帮我看一下如下脚本,动态增加一行数据,如果点击“复制”按钮,就把该行数据内容填写到新增的那行数据里。如果点“增加一行”则新增一行空白数据。
现在可以新增一行空白数据,但不知道怎么在点选“复制”后,新增一行数据,并把点选行的数据赋值到新行里。
本人对JAVASCRIPT不是很懂,求助。
<html>
<head>
<script type="text/javascript">
/**//*This function is use to add one row dynamicly
* tabObj : Target table
* colNum: The number of columns that of a row in table
* sorPos: The source of the new row.
* targPos: The position where the new row will be added.
*
*/
function addRow(tabObj,colNum,sorPos,targPos){
var nTR = tabObj.insertRow(tabObj.rows.length-targPos); // Insert a new row into appointed table on the
//appointed position.
var TRs = tabObj.getElementsByTagName('TR'); // Get TRs collection from the appointed table
var sorTR = TRs[sorPos]; // Positioned the sorTR
var TDs = sorTR.getElementsByTagName('TD'); // Get TDs collection from the appointed row
if(colNum==0 || colNum==undefined || colNum==isNaN){
colNum=tabObj.rows[0].cells.length;
}
var ntd = new Array(); // Create a new TDs array
for(var i=0; i< colNum; i++){ // Traverl the TDs in row
ntd[i] = nTR.insertCell(); // Create new cell
ntd[i].id = TDs[0].id; // copy the TD's id to new cell. | Attention! The TDs's
//suffix must be appointed
ntd[i].innerHTML = TDs[i].innerHTML; // copy the value in ntd[i]'s innerHTML from corresponding TDs
//document.write(ntd[i].innerHTML);
//alert(ntd[i].innerHTML);
}
}
/**//* This function is use to remove appointed row in appointed table
* tabObj: the appointed table
* targPos: target row position
* btnObj: currently clicked delete image button
*
*/
function deleteRow(tabObj,targPos,btnObj){ //Remove table row
for(var i =0; i<tabObj.rows.length;i++){
if(tabObj.getElementsByTagName('img')[i]==btnObj){
tabObj.deleteRow(i+targPos);
}
}
}
</script>
</head>
<body>
<form name=frmUserInfo1 action="user_list1.asp" method=post>
<br>
<table id=tabUserInfo1 border=1 width="720" cellpadding="5" cellspacing="0" bordercolor="#E8E09F">
<tr>
<td><div align="center">姓 名</div></td>
<td><div align="center">密 码</div></td>
<td><div align="center">职 位</div></td>
<td><div align="center">访问权限</div></td>
<td><div align="center">操 作</div></td>
</tr>
<tr id=trUserInfo1>
<td id=tdUserInfo1><input id=username1 name=username1 value="hxb" ></td>
<td id=tdUserInfo1><input id=usersex1 name=usersex1 value="1234"></td>
<td id=tdUserInfo1><input id=userage1 name=userage value="xs"></td>
<td id=tdUserInfo1><input id=userlove1 name=userlove value="bb"></td>
<!--<td id=tdUserInfo1><input type="submit" value="复制" /></td>-->
<td id=tdUserInfo1><input type=button value="复制" onClick="addRow(document.all.tabUserInfo,null,1,1)"></td>
</tr>
</table>
</form>
<form name=frmUserInfo action="zbList.asp" method=post>
<br>
<table id=tabUserInfo border=1 width="720" cellpadding="5" cellspacing="0" bordercolor="#E8E09F">
<tr>
<td><div align="center">姓 名</div></td>
<td><div align="center">密 码</div></td>
<td><div align="center">职 位</div></td>
<td><div align="center">访问权限</div></td>
<td><div align="center">操 作</div></td>
</tr>
<!--<tr style="display:none" id=trUserInfo>-->
<tr style="display:none" id=trUserInfo>
<td id=tdUserInfo><input id=username name=username></td>
<td id=tdUserInfo><input id=userpass name=userpass></td>
<td id=tdUserInfo><input id=userzw name=userzw></td>
<td id=tdUserInfo><input id=userrole name=userrole></td>
<td id=tdUserInfo>
<img alt="删 除" onClick="deleteRow(document.all.tabUserInfo,1,this)"></td>
</tr>
<tr>
<td colspan="5">
<div align="right">
<input type=button value="增加一行" onClick="addRow(document.all.tabUserInfo,null,1,1)">
</div></td></tr>
</table>
<table border=1 width="720" cellpadding="5" cellspacing="0" bordercolor="#E8E09F" >
<tr><td><div align="center">
<input type="submit" value="提 交" name="tj" />
</div></td></tr>
</table>
</form>
</body>
</html>