首先,表格採用的是BootStrap樣式編輯的,主要使用的是angularjs,為了方便也有jQuery的方法,在測試時需自行引入bootstrap,angularjs和jq的檔案。
<script> angular.module("myModule",[]).controller('myCtrl', function($scope) { $scope.kaohzbTitle = "考核指標維護"; $scope.search = new Object(); $scope.isdisabled=false; $scope.isInfo=false; $scope.saveDate="";//用於儲存得到的未經處理資料// $http.post請求表格式資料// 模仿請求得到的資料 var datalist=[{ id:1,zbname:"中亞賽區比賽",zbtime:"2015-12-03",zbrul1:"勝利",zbrul2:"失敗",por:"請輸入說明內容",score:"2:1",type:"支援紅方"},{ id:2,zbname:"日韓賽區比賽",zbtime:"2015-11-11",zbrul1:"勝利",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"支援藍方"},{ id:3,zbname:"歐美賽區比賽",zbtime:"2015-3-03",zbrul1:"失敗",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"雙方相同"},{ id:4,zbname:"中東賽區比賽",zbtime:"2016-1-05",zbrul1:"勝利",zbrul2:"失敗",por:"請輸入說明內容",score:"2:1",type:"支援藍方"},{ id:5,zbname:"北京賽區比賽",zbtime:"2014-12-23",zbrul1:"失敗",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"雙方相同"},{ id:6,zbname:"韓國賽區比賽",zbtime:"2015-11-01",zbrul1:"失敗",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"雙方相同"},{ id:7,zbname:"日本賽區比賽",zbtime:"2011-1-23",zbrul1:"勝利",zbrul2:"失敗",por:"請輸入說明內容",score:"2:1",type:"支援紅方"},{ id:8,zbname:"中亞賽區比賽",zbtime:"2013-12-15",zbrul1:"失敗",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"支援藍方"},{ id:9,zbname:"中亞賽區比賽",zbtime:"2015-10-17",zbrul1:"失敗",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"支援紅方"},{ id:10,zbname:"中亞賽區比賽",zbtime:"2015-11-21",zbrul1:"勝利",zbrul2:"勝利",por:"請輸入說明內容",score:"2:1",type:"支援藍方"},{ id:11,zbname:"中亞賽區比賽",zbtime:"2015-2-02",zbrul1:"失敗",zbrul2:"失敗",por:"請輸入說明內容",score:"2:1",type:"支援紅方"},{ id:12,zbname:"中亞賽區比賽",zbtime:"2015-2-05",zbrul1:"勝利",zbrul2:"失敗",por:"請輸入說明內容",score:"2:1",type:"雙方相同"}];$scope.fun=function(){ var e=window.event||arguments[0]; var src=e.srcElement||e.target; if(src.nodeName=="TD"){ var par=src.parentNode; var sd=par.getElementsByTagName("td")[0]; if(sd.firstChild.checked==true){ sd.firstChild.checked=false; }else{ $("tr td").attr("checked",false); sd.firstChild.checked=true; } } }$scope.refresh=function(){//點擊重新整理按鈕顯示表格 $scope.saveDate=datalist; // console.log("結束賦予資料"); $scope.$watch("saveDate",function(){//2016.1.20監聽列表產生資料,當發生變化時執行重新整理列表 table_page(); $scope.isshow=true; }); } $scope.save=function(){//頁面提交按鈕 console.log("準備儲存"); console.log($scope.saveDate);//只要資料改變,自動儲存到未經處理資料列表中 } //表格分頁功能 function table_page(){ var show_page=5;//每頁顯示的條數 var page_all=$("#page").children().size();//總條數 var current_page=1;//當前頁// console.log(page_all); var page_num=Math.ceil(page_all/show_page);//總頁數 var current_num=0;//用於產生頁標的計數器 var li="";//頁標元素 while(page_num>current_num){//迴圈產生頁標元素 li+='<li class="page_num"><a href="javasctip:(0)">'+(current_num+1)+'</a></li>'; current_num++; } $("#page_num_all").html(li);//添加頁標到頁面 $('#page tr').css('display', 'none');//設定隱藏 $('#page tr').slice(0, show_page).css('display', '');//設定顯示 $("#current_page").html(" "+current_page+" ");//顯示當前頁 $("#page_all").html(" "+page_num+" ");//顯示總頁數 $("#previous").click(function(){//上一頁 var new_page=parseInt($("#current_page").text())-1; if(new_page>0){ $("#current_page").html(" "+new_page+" "); tab_page(new_page); } }); $("#next").click(function(){//下一頁 var new_page=parseInt($("#current_page").text())+1;//當前頁標 if(new_page<=page_num){//判斷是否為最後或第一頁 $("#current_page").html(" "+new_page+" "); tab_page(new_page); } }); $(".page_num").click(function(){//頁標跳轉 var new_page=parseInt($(this).text()); tab_page(new_page); }); function tab_page(index){//切換對應頁標的頁面 var start=(index-1)*show_page;//開始截取的頁標 var end=start+show_page;//截取個數 $('#page').children().css('display', 'none').slice(start, end).css('display', ''); current_page=index; $("#current_page").html(" "+current_page+" "); } } }).directive('contenteditable', function() {//自訂ngModel的屬性可以用在div等其他元素中 return { restrict: 'A', // 作為屬性使用 require: '?ngModel', // 此指令所代替的函數 link: function(scope, element, attrs, ngModel) { if (!ngModel) { return; } // do nothing if no ng-model // Specify how UI should be updated ngModel.$render = function() { element.html(ngModel.$viewValue || ''); }; // Listen for change events to enable binding element.on('blur keyup change', function() { scope.$apply(readViewText); }); // No need to initialize, AngularJS will initialize the text based on ng-model attribute // Write data to the model function readViewText() { var html = element.html(); // When we clear the content editable the browser leaves a <br> behind // If strip-br attribute is provided then we strip this out if (attrs.stripBr && html === '<br>') { html = ''; } ngModel.$setViewValue(html); } } }; })</script>