天涯蝶舞
2016-08-02 15:22
<!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" />
<title>无标题文档</title>
</head>
<body>
<table id="myTable" border="1px" width="60%" bgcolor="#fff">
<tr>
<th width="30px"><input type="checkbox" name="checkbox" /></th>
<th>学号</th>
<th>姓名</th>
<th>性别</th>
<th>操作</th>
</tr>
<tr bgcolor="#fff" id="tr1" onmousemove="bgColor()">
<td width="30px"><input type="checkbox" name="checkbox" /></td>
<td>xh001</td>
<td>王小明</td>
<td>男</td>
<td width="40px"><a href="javascript:;" onclick="deleteRow(this);">删除</a></td>
<!--在删除按钮上添加点击事件 -->
</tr>
<tr>
<td width="30px"><input type="checkbox" name="checkbox" /></td>
<td>xh002</td>
<td>刘小芳</td>
<td>女</td>
<td width="40px"><a href="javascript:;" onclick="deleteRow(this)">删除</a></td>
<!--在删除按钮上添加点击事件 -->
</tr>
</table>
节点名称:
<input id="sex1" type="text"/>
<script>
function deleteRow(obj){
var tbody = document.getElementById('myTable').lastChild; //为什么这里要加上lastChild呢?
var tr = obj.parentNode.parentNode;
var con=confirm("你确定删除此行吗");
document.getElementById('sex1').value=tbody.nodeName;
if(con){tbody.removeChild(tr);}
}
</script>
</body>
</html>
http://www.imooc.com/qadetail/154879
已经有人问过这个问题了。。。这是链接。
浏览器会自动帮你添加,就跟如果你不写 <html><head></head></html>,浏览器会自动帮你添加一样,这是DOM树的标准。
JavaScript进阶篇
468783 学习 · 22528 问题
相似问题