<table class="table table-border table-bordered table-bg table-hover table-sort"> <thead> <tr class="text-c"> <th>编号</th> <th>标题</th> <th>时间</th> <th>摘要</th> <th>操作 </th> </tr> </thead> <tbody id="nr"> <!--<tr class="text-c"> </tr>--> </tbody> </table> <div id="xinxi"></div>--------------------------------------
<script type="text/javascript"> var page = 1; var title = ""; $(document).ready(function() { load(); }); /*读取----------*/ function load(){ $.ajax({ async:false, type: "post", url: "click", data: { page:page, title:title, }, dataType: "json", success: function(data) { var str = ""; for(var k in data) { str += "<tr class=‘text-c‘><td>" + data[k].id + "</td><td>" + data[k].title + "</td><td>" + data[k].time + "</td><td>" + data[k].abs + "</td><td><span class=‘caozuo‘ onclick=\"tail(‘"+ data[k].id +"‘)\">详情</span> <span class=‘caozuo‘ onclick=\"disable(‘"+ data[k].id +"‘)\">删除</span> </td></tr>"; } $("#nr").html(str); } }); var str = ""; var minys = 1; var maxys = 1; //查总页数 $.ajax({ url: "page", data: { title:title, }, type: "POST", dataType: "TEXT", success: function(d) { var arr = d.split(‘\2‘); maxys = parseInt(arr[0]); $("#allNum").html(maxys); $("#allData").html(arr[1]); str += "<ul class=‘pagination‘><li id=‘next‘>下一页</li>"; for(var i = page + 2; i > page - 3; i--) { if(i >= minys && i <= maxys) { if(i == page) { str += " <li class=‘activeP dangqian‘ bs=‘" + i + "‘>" + i + "</li> "; } else { str += "<li bs=‘" + i + "‘ class=‘list‘>" + i + "</li> "; } } } str += "<li id=‘prev‘>上一页</li></ul>"; $("#xinxi").html(str); //给上一页添加点击事件 $("#prev").click(function() { page = page - 1; if(page < 1) { page = 1; } load(); //加载数据 }) //给下一页加点击事件 $("#next").click(function() { page = page + 1; if(page > maxys) { page = maxys; } load(); //加载数据 }) //给中间的列表加事件 $(".list").click(function() { page = parseInt($(this).attr("bs")); load(); //加载数据 }) } }); } /*-------------------*/ </script>
时间: 2024-10-20 13:32:46