<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<table border = "1" id="tab">
<tr>
<td> <input type="checkbox"/> </td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
</table>
<hr>
姓名: <input type="text" id="uname" />
性别: <input type="radio" name="sex" value="男"/>男
<input type="radio" id="g" name="sex" value="女"/>女
年龄: <input type="text" id="age" />
<input type="button" value="保存" id="btn" />
</body>
</html>
<script src="public.js"></script>
<script>
$id("btn").onclick = function(){
//克隆第一行
//alert( $id("tab").children[0].children[0].tagName );
var cloneTr = $id("tab").children[0].children[0].cloneNode(true);
cloneTr.children[1].innerHTML = $id("uname").value;
var sex = "男";//默认为男
//判断女是否被选中
if( $id("g").checked ){
sex = "女";
}
cloneTr.children[2].innerHTML = sex;
cloneTr.children[3].innerHTML = $id("age").value;
$id("tab").appendChild( cloneTr );
}
</script>