欧美一区二区三区,国内熟女精品熟女A片视频小说,日本av网,小鲜肉男男GAY做受XXX网站

html ajax實現分頁代碼

錢良釵1年前10瀏覽0評論

HTML Ajax實現分頁代碼:

<script type="text/javascript">
function loadPage(page){
//設置ajax請求
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState == 4 && xhr.status == 200){
//處理數據
var data = xhr.responseText;
//將數據渲染到頁面上
document.getElementById("myTable").innerHTML = data;
}
}
//發送ajax請求
var url = "getData.php?page=" + page;
xhr.open("GET", url, true);
xhr.send();
}
</script>
<table id="myTable">
<tbody>
<tr>
<td>1</td>
<td>張三</td>
<td>20</td>
</tr>
<tr>
<td>2</td>
<td>李四</td>
<td>25</td>
</tr>
<tr>
<td>3</td>
<td>王五</td>
<td>30</td>
</tr>
</tbody>
</table>
//html中的分頁代碼
<div class="pager">
<a href="javascript:loadPage(1);">首頁</a>
<a href="javascript:loadPage(2);">上一頁</a>
<a href="javascript:loadPage(3);">下一頁</a>
<a href="javascript:loadPage(4);">尾頁</a>
</div>