87,907
社区成员
发帖
与我相关
我的任务
分享
function addtablerow(address,price,comments,address1,price1,comments1,address2,price2,comments2)
{
var row=document.createElement("tr"); //建立一行
var cell;
if(address!="")
{
cell=creatimg(address,comments); //创建一个单元格节点
row.appendChild(cell);//把单元格节点增加到建立的行中
}
if(address1!="")
{
cell=creatimg(address1,comments1);
row.appendChild(cell);
}
if(address2!="")
{
cell=creatimg(address2,comments2);
row.appendChild(cell);
}
document.getElementById("resultsbody").appendChild(row); //把行增加到id为resultsbody
row=document.createElement("tr"); //又建立一行
if(price!="")
{
cell=createRlement(address2,price); //创建一个单元格节点
row.appendChild(cell);//把单元格节点增加到建立的行中
}
if(price1!="")
{
cell=createRlement(address1,price1);
row.appendChild(cell);
}
if(price2!="")
{
cell=createRlement(address2,price2);
row.appendChild(cell);
}
document.getElementById("resultsbody").appendChild(row); //把行增加到id为resultsbody
}
function createRlement(text,text1)
{
var cell =document.createElement("td") //常见一个节点
var tableNode=document.createTextNode(text1); //创建一个文本节点
cell.appendChild(tableNode);//把文本赋值给cell
cell.setAttribute("text-align","center");
cell.setAttribute("onmouseover",function(){this.style.backgroundColor="#CBE83E"});
cell.setAttribute("onmouseout",function(){this.style.backgroundColor="#FFFFFF"});
cell.setAttribute("class","photoTitle");
return cell;//返回cell
}
function creatimg(text,text1)
{
var cell =document.createElement("td");
var a=document.createElement("a");
a.setAttribute("href","show?id="+text);
a.setAttribute("target","_blank");
var img1 =document.createElement("img");
img1.setAttribute("src",text1);
img1.setAttribute("class","pimg");
a.appendChild(img1);
cell.appendChild(a);
cell.setAttribute("border","1");
return cell;
}
function parseresult()
{
var result=xmlhttp.responseXML; //获得xmlhttp对象的responseXML的属性值
var property=null; //声明局部变量
var address="";
var price="";
var comments="";//声明局部变量
var address1="";
var price1="";
var comments1="";//声明局部变量
var address2="";
var price2="";
var comments2="";//声明局部变量
var properties=result.getElementsByTagName("book"); //返回property的子元素数组
var strInner;
var nextpage=CurPage+1
var totalpage=properties.length/PageTab;
if( CurPage==1)
{
strInner="<div style="+"background-image: url(images/nextbutton.jpg); width: 207px; height: 27px"+"><a href=\"javascript:dosearch(1)\">首页</a> <a href=\"javascript:alert('已经是第一页了!')\">前一页</a> 总共" +totalpage+ "页 <a href=\"javascript:dosearch("+nextpage+")\">下一页</a> <a href=\"javascript:TurnPage(" +properties.length+ ")\">尾页</a> <div>";
}
else if( CurPage==totalpage)
{
var qianpage=CurPage-1;
strInner="<div style="+"background-image: url(images/nextbutton.jpg); width: 207px; height: 27px"+"><a href=\"javascript:dosearch(1)\">首页</a> <a href=\"javascript:dosearch("+qianpage+")\">前一页</a> 总共" +totalpage+ "页 <a href=\"javascript:alert('已经是最后一页了!')\">下一页</a> <a href=\"javascript:TurnPage("+properties.length+ ")\">尾页</a> <div>";
}
else
{
var qianpage=CurPage-1;
strInner="<div style="+"background-image: url(images/nextbutton.jpg); width: 207px; height: 27px"+"><a href=\"javascript:dosearch(1)\">首页</a> <a href=\"javascript:dosearch("+qianpage+")\">前一页</a> 总共" +totalpage+ "页 <a href=\"javascript:dosearch("+nextpage+")\">下一页</a> <a href=\"javascript:TurnPage(" +properties.length+ ")\">尾页</a> <div>";
}
var ye=document.getElementById("ye");
ye.innerHTML=strInner
var i;
if( CurPage==1)
{
i=0
}
else
{
i=(CurPage-1)*PageTab
}
var j=CurPage*PageTab;
while (i< j)
{
property=properties[i];
address=property.getElementsByTagName("id")[0].firstChild.nodeValue; //取得address元素的第一个下级子元素
price=property.getElementsByTagName("title")[0].firstChild.nodeValue; //取得price元素的第一个下级子元素
comments=property.getElementsByTagName("img")[0].firstChild.nodeValue; //取得comments元素的第一个下级子元素
i=i+1;
if(i<properties.length)
{
property=properties[i];
address1=property.getElementsByTagName("id")[0].firstChild.nodeValue; //取得address元素的第一个下级子元素
price1=property.getElementsByTagName("title")[0].firstChild.nodeValue; //取得price元素的第一个下级子元素
comments1=property.getElementsByTagName("img")[0].firstChild.nodeValue; //取得comments元素的第一个下级子元素
i=i+1;
}
if(i<properties.length)
{
property=properties[i];
address2=property.getElementsByTagName("id")[0].firstChild.nodeValue; //取得address元素的第一个下级子元素
price2=property.getElementsByTagName("title")[0].firstChild.nodeValue; //取得price元素的第一个下级子元素
comments2=property.getElementsByTagName("img")[0].firstChild.nodeValue; //取得comments元素的第一个下级子元素
i=i+1
}
addtablerow(address,price,comments,address1,price1,comments1,address2,price2,comments2); //添加行
address="";
price="";
comments="";
address1="";
price1="";
comments1="";
address2="";
price2="";
comments2="";
}
}