[javascript]删除是出现的混乱错误 ( 积分: 20 )

  • 主题发起人 主题发起人 shanshanhao
  • 开始时间 开始时间
S

shanshanhao

Unregistered / Unconfirmed
GUEST, unregistred user!
有时候点删除按钮不删哪一行,有时候再第四行点删除,删了第三行,有时候点删除吧提交按钮给删了,下面是代码,请大家帮忙找原因>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>清空</title>
<script language=&quot;javascript&quot;>
<!--
//删除指定的行
function DeleteOneRow(tableId,rowIndex)
{
var objTable =do
cument.getElementById(tableId);
if(objTable.rows.length==1 || rowIndex==0) {
alert(&quot;对不起,你首先必须选择要删除的行!!!&quot;);
return;
}
if(confirm(&quot;确定删除?&quot;)) {
objTable.deleteRow(rowIndex);
currRowIndex = 0;
}
else
{
for(var i=1;i<objTable.rows.length;i++){
objTable.rows.cells[0].bgColor = &quot;#ffffff&quot;;
currRowIndex = 0;
}
}
}
-->
</script>
</head>
<body>
<table id=table1 border=&quot;1&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
align =center width=&quot;697&quot;
>
<form action=&quot;sample.asp&quot;
method=&quot;post&quot;
name=&quot;form1&quot;width=&quot;60%&quot;>

<tr><td height=&quot;18&quot;
> 姓名</td>
<td height=&quot;18&quot;
> 数据</td>
<td height=&quot;18&quot;
> 日期</td></tr>
<%for i=1 to 5%>
<tr>
<td><%=i%> <input type=&quot;text&quot;
name=&quot;username<%=i%>&quot;
value=&quot;<%=username%>&quot;></td>
<td> <input type=&quot;text&quot;
name=&quot;userdata<%=i%>&quot;
value=&quot;<%=userdata%>&quot;></td>
<td> <input type=&quot;text&quot;
name=&quot;sdate<%=i%>&quot;
value=&quot;<%=sdate%>&quot;></td>
<td align=&quot;center&quot;
><input type=&quot;button&quot;
value=&quot;
删除 &quot;
onclick=&quot;DeleteOneRow('table1', <%=i%>)&quot;></tr>
<tr>
<%next%>
<td><input type=&quot;submit&quot;
value=&quot;提交数据&quot;></td>
</tr>
</form>
</table>
</body>
</html>
 
有时候点删除按钮不删哪一行,有时候再第四行点删除,删了第三行,有时候点删除吧提交按钮给删了,下面是代码,请大家帮忙找原因>
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>清空</title>
<script language=&quot;javascript&quot;>
<!--
//删除指定的行
function DeleteOneRow(tableId,rowIndex)
{
var objTable =do
cument.getElementById(tableId);
if(objTable.rows.length==1 || rowIndex==0) {
alert(&quot;对不起,你首先必须选择要删除的行!!!&quot;);
return;
}
if(confirm(&quot;确定删除?&quot;)) {
objTable.deleteRow(rowIndex);
currRowIndex = 0;
}
else
{
for(var i=1;i<objTable.rows.length;i++){
objTable.rows.cells[0].bgColor = &quot;#ffffff&quot;;
currRowIndex = 0;
}
}
}
-->
</script>
</head>
<body>
<table id=table1 border=&quot;1&quot;
cellpadding=&quot;0&quot;
cellspacing=&quot;0&quot;
align =center width=&quot;697&quot;
>
<form action=&quot;sample.asp&quot;
method=&quot;post&quot;
name=&quot;form1&quot;width=&quot;60%&quot;>

<tr><td height=&quot;18&quot;
> 姓名</td>
<td height=&quot;18&quot;
> 数据</td>
<td height=&quot;18&quot;
> 日期</td></tr>
<%for i=1 to 5%>
<tr>
<td><%=i%> <input type=&quot;text&quot;
name=&quot;username<%=i%>&quot;
value=&quot;<%=username%>&quot;></td>
<td> <input type=&quot;text&quot;
name=&quot;userdata<%=i%>&quot;
value=&quot;<%=userdata%>&quot;></td>
<td> <input type=&quot;text&quot;
name=&quot;sdate<%=i%>&quot;
value=&quot;<%=sdate%>&quot;></td>
<td align=&quot;center&quot;
><input type=&quot;button&quot;
value=&quot;
删除 &quot;
onclick=&quot;DeleteOneRow('table1', <%=i%>)&quot;></tr>
<tr>
<%next%>
<td><input type=&quot;submit&quot;
value=&quot;提交数据&quot;></td>
</tr>
</form>
</table>
</body>
</html>
 
<td align=&quot;center&quot;
><input type=&quot;button&quot;
value=&quot;
删除 &quot;
onclick=&quot;DeleteOneRow('table1', <%=i%>)&quot;></tr>
修改成
<td align=&quot;center&quot;
><input type=&quot;button&quot;
value=&quot;
删除 &quot;
onclick=&quot;DeleteOneRow('table1', <%=i-1%>)&quot;></tr>
看看
 
试了,不可以.用<%=i%>的话从上往下依次删可以,但挑着删或倒着删都不行.麻烦再给看看,多谢多谢.
 
我把js的函数修改了一下,不会出现你说的问题了,怎么改成ASP的就自己动手了
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot;
Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>
<SCRIPT language=javascript>
<!--
//删除指定的行
function DeleteOneRow(trId)
{
var objTable =do
cument.getElementById(trId);
if (objTable==null){
alert(&quot;无效单元格&quot;)
return;
}
if(confirm(&quot;确定删除?&quot;)) {
objTable.removeNode(true);
}
}
-->
</SCRIPT>
<TABLE id=table1 cellSpacing=0 cellPadding=0 width=697 align=center border=1>
<FORM name=form1 action=sample.asp method=post width=&quot;60%&quot;>
<TBODY>
<TR>
<TD height=18>姓名</TD>
<TD height=18>数据</TD>
</TR>
<TR id = tr1>
<TD ><INPUT value=&quot;111&quot;
name=&quot;1111&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr1')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<TR>
<TR id = tr2>
<TD ><INPUT value=&quot;222&quot;
name=&quot;222&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr2')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<TR>
<TR id = tr3>
<TD ><INPUT value=&quot;333&quot;
name=&quot;333&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr3')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<TR>
<TR id = tr4>
<TD ><INPUT value=&quot;444&quot;
name=&quot;444&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr4')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<tr>
<TR id = tr5>
<TD ><INPUT value=&quot;555&quot;
name=&quot;444&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr5')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<tr>
<TR id = tr6>
<TD ><INPUT value=&quot;666&quot;
name=&quot;444&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr6')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<tr>
<TR id = tr7>
<TD ><INPUT value=&quot;777&quot;
name=&quot;444&quot;></TD>
<TD align=middle><INPUT id=button1 onclick=&quot;DeleteOneRow('tr7')&quot;
type=button value=&quot;
删除 &quot;
name=button1></TD>
<tr>
</FORM></TBODY></TABLE></P>
</BODY>
</HTML>
 

Similar threads

后退
顶部