javascript操作table行的问题

wizard1 2008-12-30 07:25:09
如何只在前台界面上删除GridView1指定的行,不管后台操作。。
function del(_bianh) {
debugger
if(confirm('确定删除吗?'))
{
//前台界面,删除操作GridView1行。。。如何删除呢。。最好考虑行样式

}
return false;
}

<asp:GridView ID="GridView1" runat="server" Width="100%" CellPadding="3" BackColor="White"
BorderColor="#999999" BorderStyle="None" BorderWidth="1px" GridLines="Vertical"
AutoGenerateColumns="False">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="编号">
<HeaderStyle HorizontalAlign="Center" Width="20%"/>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="EmployeeName" HeaderText="员工姓名">
<HeaderStyle HorizontalAlign="Center" Width="30%"/>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="Password" HeaderText="密码">
<HeaderStyle HorizontalAlign="Center" Width="30%"/>
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField ItemStyle-Width="20%">
<ItemTemplate>
<a href="#" onclick="javascript:del('<%#Eval("EmployeeID") %>');">删除</a>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>


在此先谢谢各位大虾了。。
...全文
126 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
CutBug 2008-12-30
  • 打赏
  • 举报
回复

<table id="tbl" width="200px" border="1">
<tr>
<td>a</td>
<td>a</td>
<td><input type="button" value="delete" /></td>
</tr>
<tr>
<td>b</td>
<td>a</td>
<td><input type="button" value="delete" /></td>
</tr>
<tr>
<td>c</td>
<td>a</td>
<td><input type="button" value="delete" /></td>
</tr>
<tr>
<td>d</td>
<td>a</td>
<td><input type="button" value="delete" /></td>
</tr>
</table>

<script language="javascript">
var tb = document.getElementById("tbl");
var inputs = document.getElementsByTagName("input");
for(var i=0;i<inputs.length;i++)
{
if(inputs[i].value=="delete")
{
inputs[i].onclick=function(n){
var irow = this.parentNode.parentNode.rowIndex;
if(confirm("Are you sure to delete row:"+(irow+1)+"?"))
tb.deleteRow(irow);//rowindex:begin with "0"
};
}
}

</script>
fcxxfcxx 2008-12-30
  • 打赏
  • 举报
回复
学习
消失的尘芥 2008-12-30
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 Rail100 的回复:]
<html>
<head>
<script type="text/javascript">
function delRow()
{
document.getElementById('myTable').deleteRow(0)
}
</script>
</head>
<body> <table id="myTable" border="1">
<tr>
<td>Row1 cell1 </td>
<td>Row1 cell2 </td>
</tr>
<tr>
<td>Row2 cell1 </td>
<td>Row2 cell2 </td>
</tr>
</table>
<br />
<input type="button" onclick="delRow()"
value="Delete f…
[/Quote]
up
yuloukong 2008-12-30
  • 打赏
  • 举报
回复
楼上正解
Rail100 2008-12-30
  • 打赏
  • 举报
回复
<html>
<head>
<script type="text/javascript">
function alertRowIndex()
{
alert(document.getElementById("tr1").rowIndex);
}
</script>
</head>
<body><table border="1">
<tr id="tr1">
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr id="tr2">
<td>Peter</td>
<td>Griffin</td>
</tr>
</table>
<br />
<input type="button" onclick="alertRowIndex()"
value="Alert row index" /></body>
</html>
Rail100 2008-12-30
  • 打赏
  • 举报
回复
<html>
<head>
<script type="text/javascript">
function delRow()
{
document.getElementById('myTable').deleteRow(0)
}
</script>
</head>
<body><table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
</table>
<br />
<input type="button" onclick="delRow()"
value="Delete first row"></body>
</html>
wizard1 2008-12-30
  • 打赏
  • 举报
回复
还有如何获取单击行的索引。
kingcsx666 2008-12-30
  • 打赏
  • 举报
回复
up
wizard1 2008-12-30
  • 打赏
  • 举报
回复
初学javascript操作table。。只会做增加不会删除。。

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧