JS中如何实现复选框全选功能
js实现复选框全选功能,代码如下所示:
<? include_once("inc/auth.inc.php"); include_once("inc/utility_all.php"); include_once("inc/utility_org.php"); $connstatus=($connstatus)?true:false; if(!isset($TYPE)) $TYPE="0"; $ITEMS_IN_PAGE=10; if(!isset($start)||$start=="") $start=0; $HTML_PAGE_TITLE=_("文件管理"); include_once("inc/header.inc.php"); ?> <script> functionopen_file(FILE_ID) { URL="read_file.php?FILE_ID="+FILE_ID; myleft=(screen.availWidth-500)/2; mytop=150 mywidth=550; myheight=300; window.open(URL,"read_file","height="+myheight+",width="+mywidth+",status=1,toolbar=no,menubar=no,location=no,scrollbars=yes,top="+mytop+",left="+myleft+",resizable=yes"); } functiondelete_file(FILE_ID,CUR_PAGE) { msg='<?=_("确认要销毁该项文件吗?")?>'; if(window.confirm(msg)) { URL="delete.php?FILE_ID="+FILE_ID+"&CUR_PAGE="+CUR_PAGE; window.location=URL; } } functiondelete_all() { delete_str=""; for(i=0;i<document.getElementsByName("file_select").length;i++) { el=document.getElementsByName("file_select").item(i); if(el.checked) {val=el.value; delete_str+=val+","; } } if(i==0) { el=document.getElementsByName("file_select"); if(el.checked) {val=el.value; delete_str+=val+","; } } if(delete_str=="") { alert("<?=_("要销毁文件,请至少选择其中一个。")?>"); document.form1.reset(); return; } msg='<?=_("确认要销毁已选中的文件吗?")?>'; if(window.confirm(msg)) { url="./delete_all.php?DELETE_STR="+delete_str+"&PAGE_START=<?=$PAGE_START?>"; window.location=url; } } functionorder_by(field,asc_desc) { window.location="index1.php?CUR_PAGE=<?=$CUR_PAGE?>&TYPE=<?=$TYPE?>&FIELD="+field+"&ASC_DESC="+asc_desc; } functionfile_troop(type) { document.form1.action="troop.php?CUR_PAGE=<?=$CUR_PAGE?>&FIELD=<?=$FIELD?>&ASC_DESC=<?=$ASC_DESC?>"; document.form1.target='_self'; document.form1.submit(); } functioncheck_all() { for(i=0;i<document.getElementsByName("file_select").length;i++) { if(document.getElementsByName("allbox")[0].checked) document.getElementsByName("file_select").item(i).checked=true; else document.getElementsByName("file_select").item(i).checked=false; } if(i==0) { if(document.getElementsByName("allbox")[0].checked) document.getElementsByName("file_select").checked=true; else document.getElementsByName("file_select").checked=false; } } functionchange_roll() { delete_str=""; for(i=0;i<document.getElementsByName("file_select").length;i++) { el=document.getElementsByName("file_select").item(i); if(el.checked) {val=el.value; delete_str+=val+","; } } if(i==0) { el=document.getElementsByName("file_select"); if(el.checked) {val=el.value; delete_str+=val+","; } } varmyselect=document.getElementById("SROLL_ID"); varindex=myselect.selectedIndex; if(delete_str=="") { alert("<?=_("要组卷文件,请至少选择其中一个。")?>"); document.form1.reset(); return; } roll_id=myselect.options[index].value; url="./change_roll.php?DELETE_STR="+delete_str+"&ROLL_ID="+roll_id+"&PAGE_START=<?=$PAGE_START?>"; location=url; } functioncheck_one(el) { if(!el.checked) document.getElementsByName("allbox")[0].checked=false; } functionshenpi_all() { delete_str=""; for(i=0;i<document.getElementsByName("file_select").length;i++) { el=document.getElementsByName("file_select").item(i); if(el.checked) {val=el.value; delete_str+=val+","; } } if(i==0) { el=document.getElementsByName("file_select"); if(el.checked) {val=el.value; delete_str+=val+","; } } if(delete_str=="") { alert("<?=_("要审批文件,请至少选择其中一个。")?>"); document.form1.reset(); return; } msg='<?=_("确认要审批通过已选中的文件吗?")?>'; if(window.confirm(msg)) { //alert(delete_str); url="./shenpi_all.php?SHENPI_STR="+delete_str+"&start=<?=$start?>"; window.location=url; } } </script> <bodyclass="bodycolor"> <? //$query="SELECTcount(*)fromRMS_FILE_NEW,RMS_ROLL,RMS_ROLL_ROOMwhereRMS_FILE_NEW.ROLL_ID=RMS_ROLL.ROLL_IDandRMS_ROLL.ROOM_ID=RMS_ROLL_ROOM.ROOM_IDandRMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."'andRMS_FILE_NEW.DEL_USER=''andSHENPISTATUS='1'"; $query="SELECTcount(*)fromRMS_FILE_NEWwhereRMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."'andRMS_FILE_NEW.DEL_USER=''andSHENPISTATUS='1'"; //echo$query."<br>"; if($TYPE!="0") $query.="andCATALOG_NO='$TYPE'"; //echo$query."<br>"; $cursor=exequery(TD::conn(),$query,$connstatus); $RMS_FILE_NEW_COUNT=0; if($ROW=mysql_fetch_array($cursor)) $RMS_FILE_NEW_COUNT=$ROW[0]; if($RMS_FILE_NEW_COUNT==0) { ?> <tableborder="0"width="100%"cellspacing="0"cellpadding="3"class="small"> <tr> <tdclass="Big"><imgsrc="<?=MYOA_STATIC_SERVER?>/static/images/notify_open.gif"align="absmiddle"><spanclass="big3"><?=_("待审批文件")?></span> </td> </tr> </table> <br> <? Message("",_("无需要审批的文件")); exit; } ?> <tableborder="0"width="100%"cellspacing="0"cellpadding="3"class="small"> <tr> <tdclass="Big"><imgsrc="<?=MYOA_STATIC_SERVER?>/static/images/notify_open.gif"align="absmiddle"><spanclass="big3"><?=_("待审批文件管理")?></span> </td> <tdalign="right"valign="bottom"class="small1"><?=sprintf(_("共%s条"),'<spanclass="big4">'.$RMS_FILE_NEW_COUNT.'</span>')?> </td> <tdalign="right"valign="bottom"class="small1"> <?=page_bar($start,$RMS_FILE_NEW_COUNT,$ITEMS_IN_PAGE)?> </td> </tr> </table> <? if($ASC_DESC=="") $ASC_DESC="1"; //if($FIELD=="") //$FIELD="FILE_CODE"; //============================显示已发布文件======================================= //$query="SELECT*fromRMS_FILE_NEW,RMS_ROLL,RMS_ROLL_ROOMwhereRMS_FILE_NEW.ROLL_ID=RMS_ROLL.ROLL_IDandRMS_ROLL.ROOM_ID=RMS_ROLL_ROOM.ROOM_IDandRMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."'andRMS_FILE_NEW.DEL_USER=''andSHENPISTATUS='1'"; $query="SELECT*fromRMS_FILE_NEWwhereRMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."'andRMS_FILE_NEW.DEL_USER=''andSHENPISTATUS='1'"; //echo$query1."<br>"; if($FIELD==""){ $query.="orderbyRMS_FILE_NEW.ADD_TIMEDESC,RMS_FILE_NEW.MOD_TIMEDESC"; } else{ $query.="orderby$FIELD"; if($ASC_DESC=="1") $query.="desc"; else $query.="asc"; } //echo$query; $query.="limit$start,$ITEMS_IN_PAGE"; if($ASC_DESC=="0") $ORDER_IMG="<imgborder=0src=\"".MYOA_STATIC_SERVER."/static/images/arrow_up.gif\"width=\"11\"height=\"10\">"; else $ORDER_IMG="<imgborder=0src=\"".MYOA_STATIC_SERVER."/static/images/arrow_down.gif\"width=\"11\"height=\"10\">"; ?> <tableclass="TableList"width="100%"> <formaction="?"method="post"name="form1"> <trclass="TableHeader"> <tdnowrapalign="center"><inputtype="checkbox"name="allbox"id="allbox_for"onClick="check_all();"></td> <tdnowrapalign="center"onClick="order_by('FILE_CODE','<?if($FIELD=="FILE_CODE")echo1-$ASC_DESC;elseecho"1";?>');"style="cursor:hand;"><u><?=_("文件号")?></u><?if($FIELD=="FILE_CODE")echo$ORDER_IMG;?></td> <tdnowrapalign="center"onClick="order_by('FILE_TITLE','<?if($FIELD=="FILE_TITLE")echo1-$ASC_DESC;elseecho"1";?>');"style="cursor:hand;"><u><?=_("文件标题")?></u><?if($FIELD=="FILE_TITLE")echo$ORDER_IMG;?></td> <tdnowrapalign="center"><?=_("密级")?></td> <tdnowrapalign="center"onClick="order_by('SEND_UNIT','<?if($FIELD=="SEND_UNIT"||$FIELD=="")echo1-$ASC_DESC;elseecho"1";?>');"style="cursor:hand;"><u><?=_("发文单位")?></u><?if($FIELD=="SEND_UNIT"||$FIELD=="")echo$ORDER_IMG;?></td> <tdnowrapalign="center"onClick="order_by('SEND_DATE','<?if($FIELD=="SEND_DATE")echo1-$ASC_DESC;elseecho"1";?>');"style="cursor:hand;"><u><?=_("发文时间")?></u><?if($FIELD=="SEND_DATE")echo$ORDER_IMG;?></td> <tdnowrapalign="center"><?=_("所属案卷")?></td><tdnowrapalign="center"><?=_("创建人")?></td> <tdnowrapalign="center"><?=_("操作")?></td> </tr> <? $cursor=exequery(TD::conn(),$query,$connstatus); $RMS_FILE_NEW_COUNT=0; while($ROW=mysql_fetch_array($cursor)) { $RMS_FILE_NEW_COUNT++; $FILE_ID=$ROW["FILE_ID"]; $FILE_CODE=$ROW["FILE_CODE"]; $FILE_TITLE=$ROW["FILE_TITLE"]; $SECRET=$ROW["SECRET"]; $SEND_UNIT=$ROW["SEND_UNIT"]; $SEND_DATE=$ROW["SEND_DATE"]; $URGENCY=$ROW["URGENCY"]; $ROLL_ID=$ROW["ROLL_ID"]; $ADD_USER=$ROW["ADD_USER"];$ADD_TIME=$ROW["ADD_TIME"]; $query1="SELECT*fromRMS_ROLLwhereROLL_ID='$ROLL_ID'"; $cursor1=exequery(TD::conn(),$query1); if($ROW=mysql_fetch_array($cursor1)) { $ROLL_NAME=$ROW["ROLL_NAME"]; $STATUS=$ROW["STATUS"]; } else { $ROLL_NAME=""; } if($SEND_DATE=='0000-00-00') $SEND_DATE=''; $FILE_TITLE=htmlspecialchars($FILE_TITLE); $SECRET=get_code_name($SECRET,"RMS_SECRET"); $URGENCY=get_code_name($URGENCY,"RMS_URGENCY"); if($RMS_FILE_NEW_COUNT%2==1) $TableLine="TableLine1"; else $TableLine="TableLine2"; ?> <trclass="<?=$TableLine?>"> <tdnowrapalign="center"> <? if($STATUS!=1) { ?> <inputtype="checkbox"name="file_select"value="<?=$FILE_ID?>"onClick="check_one(self);"></td> <? } else echo""; ?> <tdalign="center"nowrap> <ahref="javascript:open_file('<?=$FILE_ID?>');"><?=$FILE_CODE?></a> </td> <tdalign="center"><ahref="javascript:open_file('<?=$FILE_ID?>');"><?=$FILE_TITLE?></a></td> <tdnowrapalign="center"><?=$SECRET?></td> <tdnowrapalign="center"><?=$SEND_UNIT?></td> <tdnowrapalign="center"><?=$SEND_DATE?></td> <tdnowrapalign="center"><?=$ROLL_NAME?></td> <tdnowrapalign="center"><?=substr(getUserNameById($ADD_USER),0,-1);?></td> <tdnowrapalign="center"> <? if($STATUS!=1) { ?> <ahref="modify.php?FILE_ID=<?=$FILE_ID?>&start=<?=$start?>"><?=_("去审批")?></a> <? } else echo_("案卷已封"); ?> <ahref="javascript:delete_file('<?=$FILE_ID?>','<?=$CUR_PAGE?>');"><?=_("销毁")?></a> </td> </tr> <? } ?> <trclass="TableControl"> <tdcolspan="9"> <b><?=_("文件操作:")?></b> <inputtype="button"value="<?=_("批量销毁")?>"class="SmallButton"onClick="delete_all()"title="<?=_("销毁已选中文件")?>"><inputtype="button"value="<?=_("批量审批")?>"class="SmallButton"onClick="shenpi_all()"title="<?=_("批量审批已选中文件")?>"> </td> </tr> </form> </table> </body> </html>
以上所述是小编给大家介绍的JS中如何实现复选框全选,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对毛票票网站的支持!