js实现表单项的全选、反选及删除操作示例
程序员文章站
2022-04-09 16:15:21
本文实例讲述了js实现表单项的全选、反选及删除操作。分享给大家供大家参考,具体如下:
本文实例讲述了js实现表单项的全选、反选及删除操作。分享给大家供大家参考,具体如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>网站会员激活码管理</title> <script language="javascript"> function resel(){ for(i=0;i<document.form1.logs.length;i++){ //这一用法只对form表单有效 document.form1.logs[i].checked = true; //如果是实现【全不选】的话,改成false即可 } } function sesel(){ for(i=0;i<document.form1.logs.length;i++){ if(document.form1.logs[i].checked) document.form1.logs[i].checked = false; else document.form1.logs[i].checked = true; } } function delsel(){ var nid = getcheckboxitem(); if(nid==""){ alert("请选择项目!\r\n"); return ; } location.href = "member_activation.php?dopost=del&ids="+nid; } //获得选中文件的文件名 function getcheckboxitem(){ var allsel=""; if(document.form1.logs.value) return document.form1.logs.value; for(i=0;i<document.form1.logs.length;i++) { if(document.form1.logs[i].checked){ if(allsel=="") allsel=document.form1.logs[i].value; else allsel=allsel+"-"+document.form1.logs[i].value; } } //alert(allsel); //1-2-7 return allsel; } </script> </head> <body background='images/allbg.gif' leftmargin='8' topmargin='8'> <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#cfcfcf"> <tr> <td>激活码列表</td> </tr> <tr bgcolor="#fefcef" height="30" align="center"> <td width="3%">选择</td> <td width="5%">id</td> <td width="30%">激活码</td> </tr> <form name="form1"> {dede:datalist} <tr height="26" align="center" bgcolor="#ffffff" onmousemove="javascript:this.bgcolor='#fcfdee';" onmouseout="javascript:this.bgcolor='#ffffff';"><!--onmousemove/onmouseout:鼠标移动到该行后,被选中的行变色--> <td><input name='logs' type='checkbox' value='{dede:field.id/}' /></td> <td>{dede:field.id/}</td> <td>{dede:field.core/}</td> </tr> {/dede:datalist} </form> <tr bgcolor="#ffffff"> <td height="36" colspan="9"> <a class="coolbg" onclick="resel();" >全选</a> <a class="coolbg" onclick="sesel();" >反选</a> <a class="coolbg" onclick="delsel();">删除</a> </td> </tr> </table> </body> </html>
member_activation.php
//删除选定状态 if($dopost=="del") { $ids = explode('-',$ids); $dquery = ""; foreach($ids as $id) { if($dquery=="") { $dquery .= "id='$id' "; } else { $dquery .= " or id='$id' "; } } if($dquery!="") $dquery = " where ".$dquery; $dsql->executenonequery("delete from cr_member_activation $dquery"); showmsg("成功删除指定的记录!","./index.php"); exit(); }