js實(shí)現(xiàn)表單項(xiàng)的全選、反選及刪除操作示例
本文實(shí)例講述了js實(shí)現(xiàn)表單項(xiàng)的全選、反選及刪除操作。分享給大家供大家參考,具體如下:
<html xmlns='http://www.w3.org/1999/xhtml'><head><title>網(wǎng)站會(huì)員激活碼管理</title><script language='javascript'>function ReSel(){ for(i=0;i<document.form1.logs.length;i++){ //這一用法只對(duì)form表單有效document.form1.logs[i].checked = true; //如果是實(shí)現(xiàn)【全不選】的話,改成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('請(qǐng)選擇項(xiàng)目!rn'); return ; } location.href = 'http://www.aoyou183.cn/bcjs/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 border='0' cellpadding='2' cellspacing='1' bgcolor='#cfcfcf'> <tr> <td>激活碼列表</td> </tr> <tr bgcolor='#FEFCEF' align='center'> <td width='3%'>選擇</td> <td width='5%'>id</td> <td width='30%'>激活碼</td> </tr> <form name='form1'> {dede:datalist} <tr bgcolor='#FFFFFF' onMouseMove='javascript:this.bgColor=’#FCFDEE’;' onMouseOut='javascript:this.bgColor=’#FFFFFF’;'><!--onMouseMove/onMouseOut:鼠標(biāo)移動(dòng)到該行后,被選中的行變色--> <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 colspan='9'> <a onClick='ReSel();' >全選</a> <a onClick='SeSel();' >反選</a> <a onClick='DelSel();'>刪除</a> </td> </tr></table> </body></html>
member_activation.php
//刪除選定狀態(tài)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();}
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript操作DOM技巧總結(jié)》、《JavaScript頁(yè)面元素操作技巧總結(jié)》、《JavaScript事件相關(guān)操作與技巧大全》、《JavaScript查找算法技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章:
1. js select支持手動(dòng)輸入功能實(shí)現(xiàn)代碼2. asp.net core項(xiàng)目授權(quán)流程詳解3. CSS3中Transition屬性詳解以及示例分享4. jsp文件下載功能實(shí)現(xiàn)代碼5. 開(kāi)發(fā)效率翻倍的Web API使用技巧6. bootstrap select2 動(dòng)態(tài)從后臺(tái)Ajax動(dòng)態(tài)獲取數(shù)據(jù)的代碼7. vue使用moment如何將時(shí)間戳轉(zhuǎn)為標(biāo)準(zhǔn)日期時(shí)間格式8. html中的form不提交(排除)某些input 原創(chuàng)9. PHP橋接模式Bridge Pattern的優(yōu)點(diǎn)與實(shí)現(xiàn)過(guò)程10. ASP常用日期格式化函數(shù) FormatDate()
