<div class="codetitle"> <span><a style="CURSOR: pointer" data="71169" class="copybut" id="copybut71169" onclick="doCopy('code71169')"><u>複製程式碼</u></a></span> 程式碼如下:</div> <div class="codebody" id="code71169"> <br>var countPage; <br>var nowPag = 1; <br>var pageSize; <br>var countSize; <br><br>var starIndex; <br>var endo>; // 使用者提交資訊<br>var name; <br>var sex; <br>var age; <br><br>// 定義行號<br>var num = 1; <br><br>$( document).ready(function() { <br>// 註冊新增使用者的事件<br>$("#submit").click(function() { <br>// 取得使用者提交的資訊<br>name = $("#name").val(); <br>sex = $("input[name='sex']:checked").val(); <br>age = $("#age") .val(); <br>pageSize = $("#selectSize option:selected").val(); <br>// alert(name sex age pageSize); <br><br>// 建立表格下的tr物件<br>$tr = $("<tr class="data"></tr>"); <br>$td1 = $("<td></td>"); <br>$td2 = $("<td></td>"); <br>$td3 = $("<td></td>"); <br>$td4 = $("<td></td>" ); <br>$td5 = $("<td></td>"); <br><br>$tr.append($td1.append("<input type="checkbox">")); <br>$tr.append($td2.append(name)); <br>$tr.append($td3.append(sex)); <br>$tr.append($td4.append(age)) ; <br>$tr.append($td5.append("<input type="button" value="刪除">")); <br><br>$("#show").append($tr ); <br>pageNation(); <br><br>}); <br>// 註冊選擇顯示條數的操作<br>$("#selectSize").change(function() { <br> pageSize = $("#selectSize option:selected").val(); <br>pageNation(); <br>}); <br><br>// 註冊分頁操作的按鈕點選事件<br>$( "#first").click(pageNation); <br>$("#back").click(pageNation); <br>$("#next").click(pageNation); <br>$("# last").click(pageNation); <br><br>}); <br><br>// 分頁操作的函數<br>var pageNation = function() { <br>// 取得所有的資料列數<br>countSize = $("#show tr").size(); <br>// 取得總頁數<br>countPage = Math.ceil(countSize / pageSize); <br><br>//處理翻頁的操作<br>if (this.nodeType == 1) { <br>var idValue = $(this).attr("id"); <br>if ("first" == idValue) { <br>// alert(idValue); <br>nowPag = 1; <br>} else if ("back" == idValue) { <br>// alert(nowPag); <br>if (nowPag > 1) { <br>nowPag--; <br>} <br><br>} else if ("next" == idValue) { <br>// alert(idValue); <br>if (nowPag nowPag ; <br>} <br>} else if ("last" == idValue) { <br>// alert(idValue); <br>nowPag = countPage; <br>} <br><br>nowPag = countPage; <br>} <br><br>} <br>// alert(pageSize); <br>// 取得顯示開始與結束的下標<br>starIndex = (nowPag - 1) * pageSize 1; <br>endIndex = nowPag * pageSize; <br><br>if (endIndex > countSize) { <br>// alert("下標大於總記錄數" endIndex); <br>endIndex = countSize; <br>} <br><br>if (countSize // alert("總記錄數小小於每頁的顯示條數" endIndex); <br>endIndex = countSize; <br>} <br><br>// alert(starIndex); <br><br>if (starIndex == endIndex) { <br>// 顯示的操作<br>$("#show tr:eq(" (starIndex - 1) ")").show(); <br>$("#show tr:lt(" (starIndex - 1) ")").hide(); <br>} else { <br>// 顯示的操作<br>$("#show tr: gt(" (starIndex - 1) ")").show(); <br>$("#show tr:lt(" (endIndex - 1) ")").show(); <br><br> // 隱藏的操作<br>$("#show tr:lt(" (starIndex - 1) ")").hide(); <br>$("#show tr:gt(" (endIndex - 1) ")").hide(); <br>} <br>// 改變底部顯示動作<br>$("#sizeInfo") <br>.html( <br>"目前從" starIndex "條到第" endIndex "筆記錄,共" countSize <br> "筆記錄."); <br>$("#pageInfo").html("目前是第" nowPag "頁,共" countPage "p."); <br>}; <br><br><br>[html] view plaincopy在CODE上查看代碼片派生到我的代碼片<br><br> <br> <br> <br><title>用jquery實現</title> <br><br><meta name="keywords" content="keyword1,keyword2,keyword3"> <br><meta name="description" content="this is my page"> <br><meta name="content-type" content="text/html; charset=UTF-8"> <br><script type="text/javascript" src="../js/jquery-2.0.3.min.js"></script> <br><!--<link rel="stylesheet" type="text/css" href="./styles.css" >--> <br><style type="text/css"> <BR>div { <BR>border: 1px black solid; <br>} <br><BR>#tableDiv { <BR>height: 500px ; <br>} <br><BR>#insertDiv { <BR>width: 300px; <BR>margin-right: 550px; <br>} <br><BR>#tableDiv. <BR>margin-left: 350px; <BR>} <br><br>#top { <BR>width: 500px; <BR>height: 400px; <BR>} <br>} <br>? contentTable,#bottomTable { <BR>width: 450px; <BR>}<BR></樣式> <br><br><BR><script type="text/javascript" src="../js/jqueryTablePageNation.js"> <BR></頭> <br><br><身體> <BR><div id="content"align="center"> <BR><表單動作=""> <br><br><div id="insertDiv" style=" width: 263px; "> <BR><表id="insertData" border="1px"> <BR><tr> <BR><td>姓名<input type="text" id="name" value=" donghogyu"> <BR> <BR><tr> <BR><td>性別<input type="radio" name="sex" value="男" <BR>checked=" checked">男<input type="radio" name="sex" <BR>value="女">女<BR>; <br><br> <BR><tr> <BR><td>年齡<input type="text" id="age" value="21"> <BR> <BR><tr> <BR><tdalign="center "><input type="button" id="submit"<BR>value="資料新增"> <BR> <BR></表> <BR></style> </div> <br><br><div id="tableDiv"> <br><div id="top"> <br> <br> <br><br><th> <input type="checkbox">全選</th> <br>第個姓名第>個<br>性別第> <br><th>密碼</th> <br>操作第>; <br><br>頭> <br><tbody id="show"> <br><br> </tbody> <br>表> <br> </div> <br><br><div id="bottom"> <br> <br><tralign> <br><td><input type="button" value="首頁" id="first"></td> <br><td><input type="button" value="上一頁" id="back"></td> <br><td><input type="button" value="下一頁" id="next"></td> <br><td><input type="button" value="末頁" id="last"></td> <br><td> <select id="selectSize"> <br>3選項> <br>5選項> <br>10選項> <br></select>條</td> <br> <br><tralign> <br><td colspan="6"><span id="sizeInfo">目前從0筆到第0筆。 </span></td> <br> <br><tralign> <br><td colspan="6"><span id="pageInfo">目前是第0頁,共0頁。 </span></td> <br> <br>表> <br><br></tralign></tralign></tralign> </div> <br> </div> <br><br><br>表格> <br> <br>身體> <br> <br>