首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

想请问一下,小弟我下面的程序应该如何改

2012-05-03 
想请教一下,我下面的程序应该怎么改?我想用js读取xml文档之后,然后对读取的信息进行分页显示,我每页显示4

想请教一下,我下面的程序应该怎么改?
我想用js读取xml文档之后,然后对读取的信息进行分页显示,我每页显示4个,但是我这个程序只有当信息数是4的倍数时才正常,要是其他的情况就不会分页显示,帮忙看一下。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="jquery-1.2.6.js" type="text/javascript"></script>
<script language="JavaScript">
<!--
var orderDoc;
var browse="";
var items;
var fileRoute="configall.xml"
if (document.implementation && document.implementation.createDocument) //firfox 下面的处理
  {orderDoc=document.implementation.createDocument('', '', null);
  orderDoc.async=false;
  orderDoc.load(fileRoute);
  items = orderDoc.getElementsByTagName("app");
  browse="ff";
  }
  else
  {alert( '未做与该浏览器的兼容!');
  }
//根据编号获取数据,
function getDataByid(number)
{
if(browse=="ff"){ //ff 下面获得数据的方法
var SKU = orderDoc.getElementsByTagName("appid")[number].childNodes[0].nodeValue;
var PricePer = orderDoc.getElementsByTagName("icon")[number].childNodes[0].nodeValue;
var Quantity = orderDoc.getElementsByTagName("appname")[number].childNodes[0].nodeValue;
var Total = orderDoc.getElementsByTagName("type")[number].childNodes[0].nodeValue;
var Description = orderDoc.getElementsByTagName("install")[number].childNodes[0].nodeValue;
var selectContent='';
  selectContent +='<table>';
selectContent +='<tr>';
selectContent +='<td>';
selectContent +='<img src='+ PricePer +'>';
selectContent +='</td>';
selectContent +='<td>';
selectContent +='<img src="qidong.png">';
selectContent +='</td>';
selectContent +='<td>';
selectContent +='<img src="shanchu.png">';
selectContent +='</td>';
selectContent +='</tr>';
selectContent +='</table>';
selectContent +='<p>';
selectContent +='</p>';
return selectContent;
}
}
<!-- 分页显示 -->
var currentPage = 1;//当前页数
var count; //总页数
var perPage=4; //每页显示的数据量
//获得总页数
function getCount()
{
var n1 = items.length;
if(n1%4==0)
  count = n1/4;
else
  count = Math.ceil(n1/4);
}
//上一页
function prevPage()
{
  if(currentPage ==1)
  currentPage=1;
  else currentPage--;
  getContent();
}
//下一页
function nextPage()
{
  if(currentPage==count)
  currentPage=count;
  else currentPage++;
  getContent();
}
//第一页
function firstPage()
{
currentPage = 1;
getContent();
}
//最后一页
function lastPage()
{
currentPage=count;
getContent();
}
//获得页面内容
function getContent()
{
  getCount();
  var content = "<input type=button id = 'firstPage' value = '第一页' onClick='firstPage()'> "
  +"<input type=button id = 'prePage' value = '上一页' onClick='prevPage()'> "
  +"<input type=button id = 'nextPage' value = '下一页' onClick='nextPage()'> "
  +"<input type=button id = 'lastPage' value = '最后一页' onClick='lastPage()'> "
  +"第<span style='color:#ff2300;'>"+currentPage+"</span>页&nbsp"
  +"共<span style='color:#ff2300;'>"+count+"</span>页";
  document.getElementById("all").innerHTML= getDataByid(currentPage*perPage-4)+getDataByid(currentPage*perPage-3)+getDataByid(currentPage*perPage-2)+getDataByid(currentPage*perPage-1)+content;


}
// -->
</script>
</head>
<body>
<h2>应用商店本地管理</h2>
<div id='all'>
<script language="javascript">
getContent();
</script>
<div>
</body>
</html>

[解决办法]
[Quote=引用:]

JScript code
function getCount(){var n1 = items.length;if(n1%4==0)  count = n1/4;else  count = Math.ceil(n1/4);}
[解决办法]
你的浏览器javascript console有什么消息吗?

更好的办法是现在开始学习使用firebug.

热点排行