js 动态为talbe 添加行

http://www.corange.cn//uploadfiles/1106_17915.jpg


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body{background:#FFFFFF;}
</style>
<script type="text/javascript">
function add(){
var oTr = document.getElementById("addtr").rows[1];
var newTr = oTr.cloneNode(true);
document.getElementById("addtr").getElementsByTagName("tbody")[0].appendChild(newTr);
newTr.cells[0].firstChild.value = newTr.rowIndex;
document.getElementById("b1").disabled = newTr.rowIndex ==5 ;
}
</script>
</head>
<body>
<input type="button" id="b1" value="添加一行" onclick="add()" />
<table width="700" border="0" cellspacing="0" cellpadding="0" id="addtr">
<tr>
<td height="30" align="center" bgcolor="#CCCCCC">ID</td>
<td align="center" bgcolor="#CCCCCC">Username</td>
<td align="center" bgcolor="#CCCCCC">Usertype</td>
<td align="center" bgcolor="#CCCCCC">Other</td>
</tr>
<tr>
<td height="30" align="center"><input type="text" size="2" value="1" /></td>
<td align="center"><input type="text" name="username" /></td>
<td align="center">
<select name="type">
<option value="1">Administrator</option>
<option value="2">Guest</option>
</select>
</td>
<td align="center"><input type="text" name="username2" /></td>
</tr>
</table>
</body>
</html>

你可能感兴趣的:(JavaScript,html,XHTML,css)