日期:2014-05-16 浏览次数:20413 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script> //PicNum=图片的数量 //Horizontal=横向列数 //Vertical=向下行数 //Width=图片宽度 //Heigh=图片告诉 function addRow(PicNum,Horizontal,Vertical,Width,Height) { var MyTable = document.getElementById("MyTable"); var MyTbody = document.getElementById("MyTbody"); TbodyTotal=1 for (i=1;i<=Horizontal;i++){ MyTR = document.createElement("tr"); MyTR.setAttribute("id","tr"); for (j=1;j<=Vertical;j++){ MyTD = document.createElement("td"); MyTD.align = "center"; MyImg = document.createElement("img"); MyImg.height = Width; MyImg.width = Height; Mya = document.createElement("A"); Mya.href="http://www.163.com"; Mya.appendChild(MyImg); MyTD.appendChild(Mya); MyBr = document.createElement("br"); MyTD.appendChild(MyBr); MyDiv1 = document.createElement("div"); MyTxt = document.createTextNode("价格"); MyTD.appendChild(MyTxt); MyTD.appendChild(MyDiv1); MyDiv2 = document.createElement("div"); var a = document.createElement("a"); a.href = "#"; a.innerHTML = "**产品名**"; MyTD.appendChild(a); MyTD.appendChild(MyDiv2); MyTR.appendChild(MyTD); TbodyTotal++; } MyTbody.appendChild(MyTR); } } </script> </head> <body> <input type="button" value="生成" onClick="addRow(50,3,5,120,120)"> <p> </p> <table border="1" cellspacing="2" cellpadding="2" id="MyTable"> <tbody id="MyTbody"> </tbody> </table> </body> </html>