javascript方面. ( 积分: 100 )

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

shanshanhao

Unregistered / Unconfirmed
GUEST, unregistred user!
页面结构如下:
我想实现下面的功能,在没提交表单之前,如果想删除某条记录,点后面的删除按钮可以直接把该记录条删除,听说用js可以实现,可我查了好半天也没找到,请高手帮助,谢谢!!
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>清空</title>
</head>
<body>
<table 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;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
姓名</td>
<td height=&quot;18&quot;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;数据</td>
<td height=&quot;18&quot;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;日期</td></tr>
<%for i=1 to 5%>
<tr>

<td> <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;
colspan=&quot;4&quot;><input type=&quot;button&quot;
value=&quot;
删除 &quot;
></tr>
<tr>
<%next%>
<td><input type=&quot;submit&quot;
value=&quot;提交数据&quot;></td>
</tr>
</form>
</table>
</body>
</html>
 
页面结构如下:
我想实现下面的功能,在没提交表单之前,如果想删除某条记录,点后面的删除按钮可以直接把该记录条删除,听说用js可以实现,可我查了好半天也没找到,请高手帮助,谢谢!!
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>清空</title>
</head>
<body>
<table 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;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
姓名</td>
<td height=&quot;18&quot;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;数据</td>
<td height=&quot;18&quot;
>&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;日期</td></tr>
<%for i=1 to 5%>
<tr>

<td> <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;
colspan=&quot;4&quot;><input type=&quot;button&quot;
value=&quot;
删除 &quot;
></tr>
<tr>
<%next%>
<td><input type=&quot;submit&quot;
value=&quot;提交数据&quot;></td>
</tr>
</form>
</table>
</body>
</html>
 
都不是太了解行业
 
没人能解决吗?555......
 
ASP的?可以实现,我马上去找代码
//删除指定的行
function DeleteOneRow(tableId,rowIndex)// 设置table的id属性
{
var objTable =do
cument.getElementById(tableId);
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;
}
}
}
 
完整代码如下,没问题就结贴吧,
<html>
<head>
<meta http-equiv=&quot;Content-Type&quot;
content=&quot;text/html;
charset=gb2312&quot;>
<title>清空</title>
<script language=&quot;javascript&quot;>
<!--
//删除指定的行
[blue]// 前面参数是table的id值,我已经设定过了,后面是索引,这个不能错,忘记是从0开始还是1开始了,自己测一下[/blue]
function DeleteOneRow(tableId,rowIndex)
{
var objTable =do
cument.getElementById(tableId);
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> <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;
colspan=&quot;4&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>
 
thank you !
 
后退
顶部