ajax翻页效果模仿yii框架自己写的
程序员文章站
2022-06-29 12:35:05
复制代码 代码如下: ajax分页
<!doctype html>
<html>
<head>
<title>ajax分页</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
function loadxmldoc($url)
{
var xmlhttp;
if (window.xmlhttprequest)
{// code for ie7+, firefox, chrome, opera, safari
xmlhttp=new xmlhttprequest();
}
else
{// code for ie6, ie5
xmlhttp=new activexobject("microsoft.xmlhttp");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200)
{
var $data = $('<div>' + xmlhttp.responsetext + '</div>');
// alert($("#updateid", $data).html());
// document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext;
$("#updateid").replacewith($("#updateid", $data));
}
}
xmlhttp.open("get",$url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table id="updateid">
<tr><td>id</td><td>标题</td><td>时间</td></tr>
<?php if(isset($_get['p'])&&$_get['p'] == 2): ?>
<tr><td>2</td><td>222</td><td>222</td></tr>
<tr><td>2</td><td>222</td><td>222</td></tr>
<?php else: ?>
<tr><td>1</td><td>111</td><td>111</td></tr>
<tr><td>1</td><td>111</td><td>111</td></tr>
<?php endif; ?>
</table>
<div><a href="javascript:;" onclick="loadxmldoc('?p=1')">1</a><a href="javascript:;" onclick="loadxmldoc('?p=2')">2</a></div>
</body>
</html>
复制代码 代码如下:
<!doctype html>
<html>
<head>
<title>ajax分页</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
function loadxmldoc($url)
{
var xmlhttp;
if (window.xmlhttprequest)
{// code for ie7+, firefox, chrome, opera, safari
xmlhttp=new xmlhttprequest();
}
else
{// code for ie6, ie5
xmlhttp=new activexobject("microsoft.xmlhttp");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readystate==4 && xmlhttp.status==200)
{
var $data = $('<div>' + xmlhttp.responsetext + '</div>');
// alert($("#updateid", $data).html());
// document.getelementbyid("mydiv").innerhtml=xmlhttp.responsetext;
$("#updateid").replacewith($("#updateid", $data));
}
}
xmlhttp.open("get",$url,true);
xmlhttp.send();
}
</script>
</head>
<body>
<table id="updateid">
<tr><td>id</td><td>标题</td><td>时间</td></tr>
<?php if(isset($_get['p'])&&$_get['p'] == 2): ?>
<tr><td>2</td><td>222</td><td>222</td></tr>
<tr><td>2</td><td>222</td><td>222</td></tr>
<?php else: ?>
<tr><td>1</td><td>111</td><td>111</td></tr>
<tr><td>1</td><td>111</td><td>111</td></tr>
<?php endif; ?>
</table>
<div><a href="javascript:;" onclick="loadxmldoc('?p=1')">1</a><a href="javascript:;" onclick="loadxmldoc('?p=2')">2</a></div>
</body>
</html>
下一篇: 闺蜜老公说