可不可以把里面的tr弄个统一的id呢
解决方案 »
- IE8 中的数组bug, 有谁能给个解决方案?
- 用javasrcipt 怎样重写url
- 救命啊,为什么总是提示说nodeType为空对象
- submit 提交后执行问题,虽然分少了点,但是这是我全部的分数了~
- insertAdjacentElement在FireFox里替代时出现的问题
- Ext.ux.grid.RowExpander 如何设置为默认展开
- 腾讯和新浪微博中是如何做到记住最后一次输入内容的(textarea)
- 给大家一个日起输入的控件——可以减少客户端输入错误呀
- 关于下拉菜单的问题
- 高手请进:关于检索网页内容
- 正则 取出图片地址及图片alt,图片地址已经取出。现求一起取出alt=""的正则!
- 有两个行数相同的表,如何点击一个表使行变色时,让另一个表的对应行也变色
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<table width="200" border="1">
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="button" name="cancle" value="取消" onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</table>
</body>
</html>
<SCRIPT LANGUAGE="JScript">
var n = null;
function doit(obj){
var td = obj.parentNode.parentNode;
td.removeNode(true);
}
</SCRIPT><table>
<tr><td>1xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
<tr><td>2xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
<tr><td>3xxxx</td><td><input type="button" value="取消" onclick="doit(this);"></td></tr>
</table>
<table border="1" width="100%" id="table1">
<tr>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"> </td>
<td width="25%"><input type=button value="取消" onclick="delrow(this);"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><input type=button value="取消" onclick="delrow(this);"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
<td><input type=button value="取消" onclick="delrow(this);"></td>
</tr>
</table>
<script language=javascript>
function delrow(o)
{
o.parentNode.parentNode.removeNode(true);
}
</script>
IE测试过,其他浏览起没测试
<!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=gb2312" />
<title>无标题文档</title>
<script>
function delrow(o){
table = o.parentNode.parentNode.parentNode
tr = o.parentNode.parentNode
table.deleteRow(tr.rowIndex)
}
</script>
</head><body>
<table width="200" border="1">
<tr>
<td> </td>
<td> </td>
<td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="button" name="cancle" value="取消" onclick="delrow(this)"/></td>
</tr>
</table>
</body>
</html>
deleteRow和rowIndex是标准的.
测试通过.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title></head><body>
<div style="width:600px" align="center">
<table id="tb" width="200" border="1" align="left">
<tr>
<td>1</td>
<td> </td>
<td> <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
</tr>
<tr>
<td>2</td>
<td> </td>
<td> <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
</tr>
<tr>
<td>3</td>
<td> </td>
<td> <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
</tr>
<tr>
<td>4</td>
<td> </td>
<td> <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
</tr>
<tr>
<td>5</td>
<td> </td>
<td> <input type="button" name="button" onclick="del(this)" id="button" value="取消" /></td>
</tr>
</table>
<script language="javascript">
function $ (id)
{
return document.getElementById(id);
}
function del(obj)
{
var tb = $("tb"); for(var i=0;i<tb.rows.length;i++)
{
if(tb.rows[i] == obj.parentElement.parentElement)
{
tb.deleteRow(i);
return ;
}
}
}
</script>
</div>
</body>
</html>
收藏onclick="this.parentNode.parentNode.parentNode.deleteRow(this.parentNode.parentNode.rowIndex)"