jquery 全选反选

来源:互联网 发布:mac版腾讯视频 编辑:程序博客网 时间:2024/05/03 07:23

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<script type="text/javascript" src="{$base_url}images/js/jquery.js"></script>
<link href="images/css/table.css" media="screen" rel="stylesheet" type="text/css">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>{$page_title}</title>
<style>
   {literal}
       body {
            background:none repeat scroll 0 0 ;
            color:#4F6B72;
            }
        tr.odd  { background:#FFF3BF;}
        tr.highlight { background:red;}
      tr.selected{ background:#aaaaaa;color:#fff;}
      td{border-left:1px solid #C1DAD7;}
   {/literal}
</style>

<script>
var ajax_post_url = "{url_sys controller='admincp_blacklist' action='up'}";

var delUserUrl ="{url_sys controller=admincp_blacklist action=del}";
 {literal}
 

function getCheckboxItem()
{
 var allSel="";
 if(document.form2.bID.value) return document.form2.bID.value;
 for(i=0;i<document.form2.bID.length;i++)
 {
    if(document.form2.bID[i].checked)
 {
         if(allSel=="")
         allSel=document.form2.bID[i].value;
         else
         allSel=allSel+","+document.form2.bID[i].value;
 }
 }
 return allSel;
}

function selAll(){
     
     $("input[name=bID]").attr("checked",true)
 /*   for(i=0;i<document.form2.bID.length;i++)
 {
        document.form2.bID[i].checked=true;
 }*/
 
}

function noSelAll(){

     for(i=0;i<document.form2.bID.length;i++)
 {
        document.form2.bID[i].checked=false;
 }
}

  function delUser(){
   
       var b = getCheckboxItem();

       if(b){
        
          location=delUserUrl+"&bids="+b;
      
       }else{
      
         alert("请选择删除项");
      
       }
    
 
  }

  {/literal}
</script>
</head>
<body>
<form  name="form2">
<table style="margin-left:25px;" cellpadding="1" cellspacing="1" width="600" border="0" background="#fafafa">
   
    <thead>       
            <tr>
                <th align="left">编号</th>
                <th align="left">用户名</th>                           
                <th align="left">用户UID</th>
                <th align="left">当前状态</th>
                <th align="left">选择</th>
           </tr>
    </thead>
   <tbody>
         
            {foreach from=$users item=user name=user }

            <tr>
                <td>{$smarty.foreach.user.iteration}</td>
                <td>{$user.b_username}</td>
                <td>{$user.b_uid}</td>
                <td>{if $user.b_flag==0}黑名单用户{/if}</td>
                <td>
                    <input type="checkbox" class="np" value="{$user.b_id}"  name="bID">

                   
                </td>
               
            </tr>
           
            {/foreach}
            <tr>
                <td colspan="6" align="right">
                <input type="button" onclick="selAll()" value="全选"/>
                <input type="button" onclick="noSelAll()" value="取消"/>
                <input type="button" onclick="delUser()" value="删除"/></td>
            </tr>
       
        </tbody>
    </tr>
    <tfoot>
     {if $pagestr}
    <tr>
   
        <td>{$pagestr}</td>
    </tr>
    {/if}
    </tfoot>
</table>
</form>


</body>
</html>