如何由JavaScript自动生成一个5行5列的表格,表格元素为该单元格所处行...
发布网友
发布时间:2022-04-25 02:42
我来回答
共2个回答
热心网友
时间:2022-04-24 16:32
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>请您试试</title>
<script language="javascript" type="text/javascript">
function tableShow(){
document.write("<table width=800 border=1>");
for (var i = 0; i < 100; i++) {
document.write("<tr>");
for (var j = 0; j < 6; j++) {
document.write("<td>" + 100+Math.floor(900*Math.random()) + "</td>");
}
document.write("</tr>");
}
document.write("</table>");
}
</script>
</head>
<body>
<input type="button" id="button" name="button" value="点击我将出现您需要的表格" onclick="tableShow()" />
</body>
</html>
另外,站长团上有产品团购,便宜有保证
热心网友
时间:2022-04-24 17:50
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>
<div id="div_1" style="width:500px;height:500px">11</div>
</BODY>
</HTML>
<script type="text/javascript">
var tab = document.createElement("table");
for (var i=1;i<=5;i++) {
var tr = document.createElement("tr");
for (var j=1;j<=5;j++) {
var td=document.createElement("td");
td.width="80";
td.height="40";
td.innerHTML = "[row:"+i+",col:"+j+"]"
tr.appendChild(td);
}
tab.appendChild(tr);
}
document.getElementById("div_1").innerHTML = "<table border=1>"+tab.innerHTML+"</table>";
</script>追问tr.append(td)不支持属性方法!
追答修改了一下下哦~~~仔细看看吧。刚才去调试了一下,之前都是手打- -有点记不清了~~
现在是appendChild咯~
对了要给最佳哦 - -,专门给你去写的js