当前位置:Gxlcms > JavaScript > JS中如何实现复选框全选功能

JS中如何实现复选框全选功能

时间:2021-07-01 10:21:17 帮助过:7人阅读

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> 
function open_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"); 
} 
function delete_file(FILE_ID,CUR_PAGE) 
{ 
 msg='<?=_("确认要销毁该项文件吗?")?>'; 
 if(window.confirm(msg)) 
 { 
 URL="delete.php?FILE_ID=" + FILE_ID + "&CUR_PAGE=" + CUR_PAGE; 
 window.location=URL; 
 } 
} 
function delete_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; 
 } 
} 
function order_by(field,asc_desc) 
{ 
 window.location="index1.php?CUR_PAGE=<?=$CUR_PAGE?>&TYPE=<?=$TYPE?>&FIELD="+field+"&ASC_DESC="+asc_desc; 
} 
function file_troop(type) 
{ 
  document.form1.action="troop.php?CUR_PAGE=<?=$CUR_PAGE?>&FIELD=<?=$FIELD?>&ASC_DESC=<?=$ASC_DESC?>"; 
  document.form1.target='_self'; 
  document.form1.submit(); 
} 
function check_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; 
 } 
} 
function change_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 + ","; 
   } 
 }  
 var myselect=document.getElementById("SROLL_ID");  
 var index=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; 
} 
function check_one(el) 
{ 
  if(!el.checked) 
   document.getElementsByName("allbox")[0].checked=false; 
} 
function shenpi_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> 
<body class="bodycolor"> 
<? 
 // $query = "SELECT count(*) from RMS_FILE_NEW,RMS_ROLL,RMS_ROLL_ROOM where RMS_FILE_NEW.ROLL_ID=RMS_ROLL.ROLL_ID and RMS_ROLL.ROOM_ID=RMS_ROLL_ROOM.ROOM_ID and RMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."' and RMS_FILE_NEW.DEL_USER='' and SHENPISTATUS='1'"; 
  $query = "SELECT count(*) from RMS_FILE_NEW where RMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."' and RMS_FILE_NEW.DEL_USER='' and SHENPISTATUS='1'"; 
  //echo $query."<br>";  
if($TYPE!="0") 
  $query .= " and CATALOG_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) 
 { 
?> 
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small"> 
 <tr> 
  <td class="Big"><img src="<?=MYOA_STATIC_SERVER?>/static/images/notify_open.gif" align="absmiddle"><span class="big3"> <?=_("待审批文件")?></span>  
  </td> 
 </tr> 
</table> 
<br> 
<? 
  Message("",_("无需要审批的文件")); 
  exit; 
 } 
?> 
<table border="0" width="100%" cellspacing="0" cellpadding="3" class="small"> 
 <tr> 
  <td class="Big"><img src="<?=MYOA_STATIC_SERVER?>/static/images/notify_open.gif" align="absmiddle"><span class="big3"> <?=_("待审批文件管理")?></span>  
  </td> 
  <td align="right" valign="bottom" class="small1"><?=sprintf(_("共%s条"), '<span class="big4"> '.$RMS_FILE_NEW_COUNT.'</span>')?>  
  </td> 
  <td align="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 * from RMS_FILE_NEW,RMS_ROLL,RMS_ROLL_ROOM where RMS_FILE_NEW.ROLL_ID=RMS_ROLL.ROLL_ID and RMS_ROLL.ROOM_ID=RMS_ROLL_ROOM.ROOM_ID and RMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."' and RMS_FILE_NEW.DEL_USER='' and SHENPISTATUS='1'"; 
  $query = "SELECT * from RMS_FILE_NEW where RMS_FILE_NEW.shenpiren='".$_SESSION["LOGIN_USER_ID"]."' and RMS_FILE_NEW.DEL_USER='' and SHENPISTATUS='1'"; 
  //echo $query1."<br>"; 
  if($FIELD==""){ 
  $query.=" order by RMS_FILE_NEW.ADD_TIME DESC,RMS_FILE_NEW.MOD_TIME DESC";  
  } 
  else { 
    $query .= " order by $FIELD"; 
if($ASC_DESC=="1") 
  $query .= " desc"; 
else 
  $query .= " asc"; 
    }                   
//echo $query; 
$query .= " limit $start,$ITEMS_IN_PAGE"; 
if($ASC_DESC=="0") 
  $ORDER_IMG="<img border=0 src=\"".MYOA_STATIC_SERVER."/static/images/arrow_up.gif\" width=\"11\" height=\"10\">"; 
else 
  $ORDER_IMG="<img border=0 src=\"".MYOA_STATIC_SERVER."/static/images/arrow_down.gif\" width=\"11\" height=\"10\">"; 
?> 
<table class="TableList" width="100%"> 
 <form action="?" method="post" name="form1"> 
 <tr class="TableHeader"> 
   <td nowrap align="center"><input type="checkbox" name="allbox" id="allbox_for" onClick="check_all();"></td> 
   <td nowrap align="center" onClick="order_by('FILE_CODE','<?if($FIELD=="FILE_CODE") echo 1-$ASC_DESC;else echo "1";?>');" style="cursor:hand;"><u><?=_("文件号")?></u><?if($FIELD=="FILE_CODE") echo $ORDER_IMG;?></td> 
   <td nowrap align="center" onClick="order_by('FILE_TITLE','<?if($FIELD=="FILE_TITLE") echo 1-$ASC_DESC;else echo "1";?>');" style="cursor:hand;"><u><?=_("文件标题")?></u><?if($FIELD=="FILE_TITLE") echo $ORDER_IMG;?></td> 
   <td nowrap align="center"><?=_("密级")?></td> 
   <td nowrap align="center" onClick="order_by('SEND_UNIT','<?if($FIELD=="SEND_UNIT"||$FIELD=="") echo 1-$ASC_DESC;else echo "1";?>');" style="cursor:hand;"><u><?=_("发文单位")?></u><?if($FIELD=="SEND_UNIT"||$FIELD=="") echo $ORDER_IMG;?></td> 
   <td nowrap align="center" onClick="order_by('SEND_DATE','<?if($FIELD=="SEND_DATE") echo 1-$ASC_DESC;else echo "1";?>');" style="cursor:hand;"><u><?=_("发文时间")?></u><?if($FIELD=="SEND_DATE") echo $ORDER_IMG;?></td> 
   <td nowrap align="center"><?=_("所属案卷")?></td> <td nowrap align="center"><?=_("创建人")?></td> 
   <td nowrap align="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 * from RMS_ROLL where ROLL_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"; 
?> 
  <tr class="<?=$TableLine?>"> 
   <td nowrap align="center"> 
<? 
if($STATUS!=1) 
{ 
?> 
    <input type="checkbox" name="file_select" value="<?=$FILE_ID?>" onClick="check_one(self);"></td> 
<? 
} 
else 
  echo " "; 
?> 
   <td align="center" nowrap> 
   <a href="javascript:open_file('<?=$FILE_ID?>');"><?=$FILE_CODE?></a> 
   </td> 
   <td align="center"><a href="javascript:open_file('<?=$FILE_ID?>');"><?=$FILE_TITLE?></a></td> 
   <td nowrap align="center"><?=$SECRET?></td> 
   <td nowrap align="center"><?=$SEND_UNIT?></td> 
   <td nowrap align="center"><?=$SEND_DATE?></td> 
   <td nowrap align="center"><?=$ROLL_NAME?></td> 
    <td nowrap align="center"><?=substr(getUserNameById($ADD_USER),0,-1);?></td> 
   <td nowrap align="center"> 
<? 
if($STATUS!=1) 
{ 
?> 
   <a href="modify.php?FILE_ID=<?=$FILE_ID?>&start=<?=$start?>"> <?=_("去审批")?></a> 
<? 
} 
else 
  echo _("案卷已封"); 
  ?> 
  <a href="javascript:delete_file('<?=$FILE_ID?>','<?=$CUR_PAGE?>');"> <?=_("销毁")?></a> 
   </td> 
  </tr> 
<? 
 } 
?> 
<tr class="TableControl"> 
<td colspan="9"> 
  <b><?=_("文件操作:")?></b> 
  <input type="button" value="<?=_("批量销毁")?>" class="SmallButton" onClick="delete_all()" title="<?=_("销毁已选中文件")?>">  <input type="button" value="<?=_("批量审批")?>" class="SmallButton" onClick="shenpi_all()" title="<?=_("批量审批已选中文件")?>"> 
</td> 
</tr> 
</form> 
</table> 
</body> 
</html> 

以上所述是小编给大家介绍的JS中如何实现复选框全选,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

人气教程排行