1、讀取json分頁javascript
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>ajax</title> <script src="ajax.js"></script> <script> //請求服務器上面的數組json分頁,ajax window.onload = function() { var oUl = document.getElementById('ul1') var aBtn = document.getElementsByTagName('a'); var i = 0; for (i = 0; i < aBtn.length; i++) { aBtn[i].index = i; aBtn[i].onclick = function() { ajax(this.index + 1 + '.txt', function(str) { var aData = eval(str); oUl.innerHTML = ""; for (i = 0; i < aData.length; i++) { var oLi = document.createElement('li'); oLi.innerHTML = '<strong>' + aData[i].user + '</strong><i>' + aData[i].pass + '<i>'; oUl.appendChild(oLi); } }) } } } </script> </head> <body> <ul id="ul1"> </ul> <a href="javascript:;">1</a> <a href="javascript:;">2</a> <a href="javascript:;">3</a> </body> </html>