菜的
2016-10-25 22:37
<!DOCTYPE html>
<html>
<head>
<title> new document </title>
<meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
<script type="text/javascript">
//修改鼠标over,out的颜色
window.onload = function(){
var tr = document.getElementsByTagName("tr");
for(var i=0;i<tr.length;i++){
tr[i].onmouseover=function(){t.style.color="#f2f2f2";}
tr[i].onmouseout=function(){t.style.color="#fff";}
}
}
//删除一行
function delete(obj){
var tr=obj.parentNode.parentNode;
tr.parentNode.removeChild(tr);
}
//增加一行
var num=2;
function click(){
num++;
var tr = document.createElement("tr");
var td1 = document.createElement("td");
var td2 = document.createElement("td");
var td3 = document.createElement("td");
td1.innerHTML="xh00"+num;
td2.innerHTML="刘俊";
td3.innerHTML="<a href='javascript:;' onclick='delete()'>删除</a>";
var tab=document.getElementById("table");
tab.appendChild(tr);
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.onmouseover=function(){t.style.color="#f2f2f2";}
tr.onmouseout=function(){t.style.color="#fff";}
}
</script>
</head>
<body>
<table border="1" width="50%" id="table">
<tr>
<th>学号</th>
<th>姓名</th>
<th>操作</th>
</tr>
<tr id="id2">
<td>xh001</td>
<td>王小明</td>
<td><a href="javascript:;" onclick="delete(this)"; >删除</a></td>
</tr>
<tr id="id3">
<td>xh002</td>
<td>刘小芳</td>
<td><a href="javascript:;" onclick="delete(this)";>删除</a></td>
</tr>
</table>
<input type="button" value="添加一行" onclick="click()" />
</body>
</html>
delete和click是javascript中的关键字,不能用作函数名
JavaScript进阶篇
468061 学习 · 21891 问题
相似问题