html xmlns="http://www.w3.org/1999/xhtml">
head>
meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
title>無標題文檔/title>
script src="jquery-1.11.2.min.js">/script>
style type="text/css">
.dangqian{ background-color:#69F}
/style>
/head>
body>
div>
input type="text" id="key" />
input type="button" value="查詢" id="chaxun" />
/div>
table width="100%" border="1" cellpadding="0" cellspacing="0">
tr>
td>代號/td>
td>名稱/td>
td>父級代號/td>
/tr>
tbody id="nr">
/tbody>
/table>
div id="xinxi">
/div>
/body>
script type="text/javascript">
var page = 1; //當前頁 定義一個變量 當前頁
Load(); //加載數(shù)據(jù)
LoadXinXi(); //加載分頁信息
//查詢
$("#chaxun").click(function(){
page = 1;
Load(); //加載數(shù)據(jù)
LoadXinXi(); //加載分頁信息
})
function Load()
{
var key = $("#key").val(); //查詢條件
$.ajax({
url:"chuli.php",
data:{page:page,key:key},
type:"POST",
dataType:"JSON",
success: function(data){
var str = "";
for(var k in data)
{
str +="tr>td>"+data[k].AreaCode+"/td>td>"+data[k].AreaName+"/td>td>"+data[k].ParentAreaCode+"/td>/tr>";
}
$("#nr").html(str);//把數(shù)據(jù)返回表格
}
});
}
functionLoadXinXi()
{
var str = "";
var minys = 1;
var maxys = 1;
var key = $("#key").val();
//查總頁數(shù)
$.ajax({
async:false,
url:"zys.php",
data:{key:key},
type:"POST",
dataType:"TEXT",
success: function(d){
maxys = d;
}
});
str += "span>總共:"+maxys+"頁/span> nbsp;";
str += "span id='prev'>上一頁/span>";
for(var i=page-2;ipage+3;i++)
{
if(i>=minys i=maxys)
{
if(i==page)
{
str += "span class='dangqian' bs='"+i+"'>"+i+"/span> nbsp;";
}
else
{
str += "span class='list' bs='"+i+"'>"+i+"/span> nbsp;";
}
}
}
str += "span id='next'>下一頁/span>";
$("#xinxi").html(str);
//給上一頁添加點擊事件
$("#prev").click(function(){
page = page-1;
if(page1)
{
page=1;
}
Load(); //加載數(shù)據(jù)
LoadXinXi(); //加載分頁信息
})
//給下一頁加點擊事件
$("#next").click(function(){
page = page+1;
if(page>maxys)
{
page=maxys;
}
Load(); //加載數(shù)據(jù)
LoadXinXi(); //加載分頁信息
})
//給中間的列表加事件
$(".list").click(function(){
page = parseInt($(this).attr("bs"));
Load(); //加載數(shù)據(jù)
LoadXinXi(); //加載分頁信息
})
}
/script>
?php
include("DBDA.class.php");
$db = new DBDA();
$page = $_POST["page"];
$key = $_POST["key"];
$num = 20;
$tiao = ($page-1)*$num;
$sql = "select * from chinastates where areaname like '%{$key}%' limit {$tiao},{$num}";
echo $db->JSONQuery($sql);