checkbox 全部選中,全部去除選中js代碼

<%@ page language="java" pageEncoding="utf-8"%>
<div id="modal-dataInfo" tabindex="-1" data-backdrop="static" class="modal fade" style="margin-top: -50px;display:none;width:800px;">
  <div class="modal-dialog">
	<div class="modal-content">           	
              <div class="modal-header" id="modal-stackable-label"> 
                  <button type="button" data-dismiss="modal" aria-hidden="true" id="closeId" class="close">&times;</button>
                  <h4 class="modal-title">節目列表</h4>
              </div>
              <div class="modal-body">
	          	 <table class="ul-form">
               		<tr><td width="80px;" align="right">節目名稱:</td>
						<td width="130px;">
			            	<input id="recordname" type="text" />
			            </td>
 						<td colspan="2">
							<button style="margin-bottom: 5px;" class="btn btn-primary" οnclick="toPage_panelInfoData(1,2);">查詢</button>
                			<button style="margin-bottom: 5px;" class="btn btn-primary" οnclick="saveData();">保存</button>
						</td>
					</tr>
				</table>
				<table id="dataInfoTable" class="table table-striped table-bordered" style="">
                        <thead>
                            <tr>
                                <th>
                                   <input type="checkbox" id="changeBox" οnclick="checkAll(this,'panelId');"/>
                                </th>
                                <!-- <th style="width: 10%">節目ID</th> -->
                                <th style="width: 35%">節目名稱</th>
                                <th style="width: 20%">節目狀態</th>
                                <th style="width: 30%">節目類型</th>
                            </tr>
                        </thead>
                        <tbody></tbody>
                    </table>
                    <div class="text-center center" style="">
                    	<input type="hidden" value="" id="hidden_flg">
                        <input type="hidden" value="1" id="current">
                                                                            當前第<input id="resourcePageNo_dataInfo" type="text" style="width:30px;height:20px;"/>/<span id="resourceTotalPage_dataInfo"></span>頁&nbsp;&nbsp;
                                                                             共<span id="resourceTotalRecord_dataInfo"></span>條數據  
                        <span id="previous_dataInfo"><a href="#" οnclick="previous_dataInfo()" >上一頁</a></span>
                        <span id="next_dataInfo"><a href="#" οnclick="next_dataInfo()">下一頁</a></span>
                    </div>
	          </div>
          </div>
      </div>
  </div>
<script type="text/javascript">
//全選、全不選
function checkAll(obj, cName) {  
	var checkboxs = document.getElementsByName(cName);  
	for ( var i = 0; i < checkboxs.length; i+=1) {  
		checkboxs[i].checked = obj.checked;  
	}  
}
//上一頁
function previous_dataInfo() {
    var current = $("#resourcePageNo_dataInfo").val();
    var reg = new RegExp("^[0-9]*$");
    if(!reg.test(current)){
        alert("頁碼請輸入數字!");
        return false;
    }
    current = parseInt(current);
    if (current>1){
        current=current-1;
    }
    $("#resourcePageNo_dataInfo").val(current);
    //頁面封裝的查詢方法
    toPage_panelInfoData(current,2);
}
//下一頁
function next_dataInfo(){
    var current = $("#resourcePageNo_dataInfo").val();
    var reg = new RegExp("^[0-9]*$");
    if(!reg.test(current)){
        alert("頁碼請輸入數字!");
        return false;
    }
    current = parseInt(current)+1;
    var resourceTotalPage = parseInt($("#resourceTotalPage_dataInfo").html());
    if(current>resourceTotalPage){
        return false;
    }
    $("#resourcePageNo").val(current);
    //頁面封裝的查詢方法
    toPage_panelInfoData(current,2);
}
 function choiceData() {
	  var seriesId = document.getElementById("seriesId").value;
	  if(seriesId ==null  || seriesId =="null" || seriesId ==""){
		 $.jBox.error('請選擇系列!', '系統提示', ''); 
	     return;
	  }
 	  $("#modal-dataInfo").modal('show');
      $("#dataInfoTable tbody tr").empty("");
      document.getElementById("resourcePageNo_dataInfo").value="";
      document.getElementById("resourceTotalPage_dataInfo").innerText="";
      document.getElementById("resourceTotalRecord_dataInfo").innerText="";
      toPage_panelInfoData(1);
 }
 webapp='${ctx}';
 function toPage_panelInfoData(pageNo){
 	var datainfoname = document.getElementById("recordname").value;
 	$.ajax({
         type : "POST",
         url : webapp + "/seriesrecordmap/seriesRecordMap/getRecordInfo",
         dataType : "json",
         data : {"name":datainfoname,"pageNo":pageNo},
         error : function(data) {
             //alert('操作失敗!');
         },
         success : function(data) {
         	 $("#dataInfoTable thead tr").empty("");
         	 $("#dataInfoTable tbody tr").empty("");
              var dataInfoTablethead = $("#dataInfoTable > thead");
              var dataInfoTable = $("#dataInfoTable > tbody");
         	 var html="";
         	 var list = data.result;
         	// var theadstr='<th style="width: 10%"><input type="checkbox" id="changeBox" οnclick="checkAll(this,\"panelId\");"/></th><th style="width: 35%">名稱</th><th style="width: 20%">節目狀態</th><th style="width: 35%">節目類型</th>';
         	 var theadstr="<th style=\"width: 10%\"><input type=\"checkbox\" id=\"changeBox\" οnclick=\"checkAll(this,'panelId');\"/></th><th style=\"width: 35%\">名稱</th><th style=\"width: 20%\">節目狀態</th><th style=\"width: 20%\">節目類型</th><th style=\"width: 15%\">排序號</th>";
			 dataInfoTablethead.html(theadstr);
          	 for(i=0; i<list.length;i++){
          		 html+="<tr><td><input type=\"checkbox\" name=\"panelId\" value=\""+list[i].id+"\"/></td>";
                  // html+='<td>'+list[i].id+'</td>';
                   html+='<td>'+list[i].name+'</td>';
                   html+='<td>';
                   var injectionFlg = list[i].injectionFlg;
                   if(injectionFlg==1){
                   	   html+="注入成功";
                   }else{
                	   html+="注入成功";
                   }
				   html+="</td>";
                   html+='<td>';
                   var type= list[i].type;
                   if(type==1){
	                   html+="錄播";
                   }else{
	                   html+="點播";
                   }

				   html+="</td>";
				   html+="<td><input type=\"text\" id=\""+list[i].id+"\" name=\"sort\" value=\"\"  οnkeyup=\"this.value=this.value.replace(/\D/g,'')\" style=\"width:50px;margin:0;padding:0;text-align:center;height: 15px;\" /><span style=\"color: red;\">*</span></tr></td>";
                   html+='</tr>';
                   //html+='<td><img src="'+list[i].url+'" style="max-width: 100px;max-height: 100px;"></td></tr>';
               }
         	 dataInfoTable.html(html);
         	 $("#resourcePageNo_dataInfo").val(data.pageNo);
              $("#resourceTotalRecord_dataInfo").html(data.totalRecord);
              $("#resourceTotalPage_dataInfo").html(data.totalPage);
              if(data.pageNo == 1){
                  $("#previous_dataInfo").html("上一頁");
              }else{
                  $("#previous_dataInfo").html("<a href='#' οnclick='previous_dataInfo()'>上一頁</a>");
              }
              if(data.pageNo == data.totalPage){
                  $("#next_dataInfo").html("下一頁");
              }else{
                  $("#next_dataInfo").html("<a href='#' οnclick='next_dataInfo()'>下一頁</a>");
              }
         }
     });
}
        
function saveData(){
	 getCheckBox(0);
}
         
  //獲取選中
  function getCheckBox(isSingle) {
      var ids = "";
      var idArr = new Array();
      $('input[name="panelId"]:checked').each(function(){ 
     	 var pid = $(this).val();
     	 var sor = $("#"+pid).val()
     	 if(sor==null||sor==""){
     		 sor="-1";
     	 }
     	 
          idArr.push(pid+"_"+sor);//向數組中添加元素  
      });
      /* $('input[name="panelId"]:checked').each(function(){ 
     	 var pid = $(this).val();
          idArr.push(pid);//向數組中添加元素  
      }); */
      //可以多選
      if(isSingle==0){
          if(idArr.length==0){
              alert("未選擇數據!");
              return;
          } else{
              for(var i=0; i<idArr.length; i++){
                  ids += idArr[i] + ",";
              }
          }
      }else{
          if(idArr.length==0){
              alert("未選擇數據!");
              return;
          } else if(idArr.length>1){
              alert("只能選中一條記錄!");
              return ;
          }
      }
      var seriesId = document.getElementById("seriesId").value;
      var recordId = document.getElementById("recordName").value;
      $.ajax({
          type : "POST",
          url : webapp + "/seriesrecordmap/seriesRecordMap/saveRecordInfo",
          dataType : "json",
          data : {"seriesId":seriesId,"ids":ids},
          error : function(data) {
              //alert('操作失敗!');
          },
          success : function(data) {
        	  if(data.message=="success"){
                  alert("保存成功!");
                  var returnUrl = webapp + "/seriesrecordmap/seriesRecordMap/list?seriesId="+seriesId+"&recordName="+recordId;
                  
                  window.location.href = returnUrl;
              }else{
                  alert("保存失敗!")
              }
          }
      });
      $("#modal-dataInfo").modal('hide');
  }
</script>

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章