1 document.onclick = function () {//这个函数将输出类似于国际象棋的棋盘 2 var tempx = 0; //x坐标 3 var tempy = 0; //y坐标 4 var temps = 14; //每行放多少个 5 for (var i = 0; i < 500; i++) { 6 var divs = document.createElement("div"); 7 divs.id = i; 8 divs.style.width = "100px"; 9 divs.style.height = "100px"; 10 if (i % 2 == 0) { 11 divs.style.borderColor = "blue"; 12 } 13 else { 14 divs.style.borderColor = "red"; 15 } 16 divs.style.borderWidth = "1px"; 17 divs.style.borderStyle = "dotted"; 18 divs.style.align = "center"; 19 divs.style.position = "absolute"; 20 tempx = (i % temps) * 100; //这里费脑筋 21 tempy = (Math.floor(i / temps)) * 100; //这里花了不少脑力 22 divs.style.left = tempx + "px"; 23 divs.style.top = tempy + "px"; 24 divs.innerHTML = i + 1; 25 document.body.appendChild(divs); 26 } 27 }
时间: 2024-10-24 21:38:18