87,903
社区成员
发帖
与我相关
我的任务
分享
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);
cell.appendChild(a);
cell.appendChild(img1);
alert(cell.outerHTML);
return cell;
}
<html>
<body>
<script>
function creatimg(text,text1)
{
var cell =document.createElement("td");
var a=document.createElement("a");
a.innerText=text;
a.setAttribute("href",text1);
a.setAttribute("target","_blank");
var img1 =document.createElement("img");
img1.setAttribute("src",text1);
cell.appendChild(a);
cell.appendChild(img1);
document.body.appendChild(a);
}
window.onload=function(){
creatimg("sdfsfs","http://www.google.com");}
</script>
</body>
</html>
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)
{
alert(text1);
var cell =document.createElement("td") //常见一个节点
var divc =document.createElement("div") //创建一个DIV一个节点
var tableNode=document.createTextNode(text1); //创建一个文本节点
var a=document.createElement("a")
a.setAttribute("href","show?id"+text);
a.setAttribute("target","_blank");
divc.appendChild(a);
var f=document.createElement("font")//创建一个字节点
f.setAttribute("face","Arial");
f.appendChild(tableNode);
divc.appendChild(f);
cell.appendChild(divc);//把文本赋值给cell
cell.setAttribute("class","photoTitle");
alert(cell.outerHTML);
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);
cell.appendChild(a);
cell.appendChild(img1);
return cell;
}
</script>
<script type ="text/javascript" >
var CurPage=0; //当前页
var PageTab=12; //每组显示页数
var CurTab=0; //当前分组
function createxmlhttp()
{
if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
}
function dosearch(val)
{
CurPage=val;
createxmlhttp();
xmlhttp.onreadystatechange=chengejieguo;
xmlhttp.open("GET","wedding.xml",true);
xmlhttp.send(null);
}
function chengejieguo()
{
if (xmlhttp.readyState==4)
{
if(xmlhttp.status==200)
{
clearpreviousresult(); //调用clearpreviousresult函数 删除以前的结果
parseresult(); //调用parseresult函数 返回结果
}
}
}
function clearpreviousresult()
{
var tablebody=document.getElementById("resultsbody"); ;//获取id 为"resultsbody"的tbody赋给tablebody变量
while(tablebody.childNodes.length>0)
{
tablebody.removeChild(tablebody.childNodes[0]); //删除子元素
}
}
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("wedding"); //返回property的子元素数组
var strInner;
var nextpage=CurPage+1
var totalpage=properties.length;
if( CurPage==1)
{
strInner="<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> ";
}
else if( CurPage==totalpage)
{
var qianpage=CurPage-1;
strInner="<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> ";
}
else
{
var qianpage=CurPage-1;
strInner="<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> ";
}
var ye=document.getElementById("ye");
ye.innerHTML=strInner
var i;
if( CurPage==1)
{
i=0
}
else
{
i=CurPage-1
}
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="";
}
}