#FormatTableID_0#
<html>
<head>
<title>新聞列表簡化型</title>
<script language="javascript">
<!--
//ajax 控件也可以做成單獨文件方便到其它地方調用
function Ajax()
{
var xhrObj=null;
if(window.XMLHttpRequest)
{
xhrObj=new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
try{
xhrObj=new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e1)
{
try{
xhrObj=new ActiveXObject("MSXML2.XMLHTTP");
}
catch(e2){
try{
xhrObj=new ActiveXObject("MSXML3.XMLHTTP");
}
catch(e3){
alert("創建Ajax失敗:"+e3)
}
}
}
}
else
{
alert("未能識別的浏覽器");
}
return xhrObj;
}
function $(id)
{
return document.all[id];
}
</script>
<script language="javascript" defer>
var xhr=new Ajax();
var page=0;
var icount=0; //當前頁數
var pagecount; //總頁數
var count=0;
var ipagecount=0;
var ipagesize=5;; //每頁顯示記錄數
var pp=0;
var ipage=0;
var Dom=null;
function getList(curPage)
{
if(ipagecount!=0)
{
ipage=parseInt((curPage-1)/ipagecount)+1;
}else{
ipage=1
};
page=curPage;
if (pp!=ipage)
{;
Dom=null;
pp=ipage;
xhr.open("get","data.asp?curpage="+pp,true);
xhr.onreadystatechange=$CallBack;
xhr.send(null);
}
else
{
$showList();
}
}
function $CallBack()
{
if(xhr.readystate==1)
{
$("newsList").innerHTML="正在連結服務器";
}
else if(xhr.readystate==2 || xhr.readystate==3)
{
$("newsList").innerHTML="正在讀取數據";
}
else if(xhr.readystate==4)
{
if (xhr.status==200)
{
Dom=xhr.responseXML;
$showList();
}
}
}
function $showList()
{
var html="";
var items=Dom.selectNodes("//item");
icount=Dom.selectNodes("//item").length; //數量
count=Dom.selectSingleNode("//data").getAttribute("count"); //總數量
ipagecount=parseInt((icount-1)/ipagesize)+1;
pagecount=parseInt((count-1)/ipagesize)+1;
startPosition=(page-1)*ipagesize;
endPosition=(page*ipagesize)
if(endPosition>count)endPosition=count
for(var i=startPosition;i<endPosition;i++)
{
html+="<div id="title"><a href=""+items[i].selectSingleNode("htmlurl").text+"">"+items[i].
selectSingleNode("hits").text+"</a></div>";
}
$("newsList").innerHTML=html;
var statushtml="<a href="javascript:previousPage()">上一頁</a>|<a href="javascript:nextPage()">下一頁</a>";
if(pagecount<=10)
{
for(var i=1;i<=pagecount;i++)
{
if (i==page)
{
statushtml+="<b>"+i+"</b> "
}
else
{
statushtml+="<a href="javascript:turnPage("+i+")">"+i+"</a> "
}
}
}
else if(page+10<pagecount && pagecount>10)
{
if(page%10==0)
{
for(var i=page-9;i<=page+1;i++)
{
if (i==page)
{
statushtml+="<b>"+i+"</b> "
}
else
{
statushtml+="<a href="javascript:turnPage("+i+")">"+i+"</a> "
}
}
}
else if(page % 10 ==1 && page!=1)
{
for(var i=page-1;i<=page+10;i++)
{
if (i==page)
{
statushtml+="<b>"+i+"</b> "
}
else
{
statushtml+="<a href="javascript:turnPage("+i+")">"+i+"</a> "
}
}
}
else if(