日期:2014-05-16 浏览次数:20690 次
本例实现 jquery + php 无刷新分页.FF IE 等浏览器均支持
index.php
<?php
header("Content-Type:text/html;charset=utf-8");
?>
<html>
<head>
<title>JQ-无刷新分页 by:siyuantlw</title>
<style>
A{text-decoration:none;}
A:link {COLOR:#33CCFF;}
A:active {COLOR:#FF6666;}
A:visited {COLOR:#33CCFF;}
A:hover {COLOR:#FF6699; TEXT-DECORATION: underline;position:relative;left:1px;top:1px}
</style>
<script src="jquery-1.5.1.js"></script>
<script language="javascript">
$(document).ready(function(){
changepage(1);
});
function changepage(page){
$.post("sql.php",{page:page},function(data){
$("#test").html(data);
});
}
</script>
</head>
<body>
<ul id="test"></ul>
</body>
</html>
sql.php
<?php
mysql_connect("","root","");
mysql_select_db("test");
mysql_query("set names utf8");
if(isset($_POST["page"])){
@$page = max(1, intval($_POST["page"]));
$pagesize=10;
$startindex=($page-1)*$pagesize;
$sql="SELECT * FROM test ORDER BY id LIMIT $startindex,$pagesize";
$rec=mysql_query($sql);
while($row=mysql_fetch_array($rec)){
$str.="<li>".$row["uname"]."</li>";
}
$num=mysql_num_rows(mysql_query("select * from test"));
$pagenum=@ceil($num/$pagesize);
for($i=1;$i<=$pagenum;$i++){
if($page==$i){
$str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>[".$i."]</a> ";
}else{
$str.="<a href='javascript:void(0)' onclick=changepage(".$i.")>".$i."</a> ";
}
}
echo $str;