欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-07-04 22:11:17
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> 
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中如何实现复选框全选,希望对大家有所帮助