1个回答
展开全部
<html>
<head>
<style>
*{margin:0;padding:0;}
table{border-collapse:collapse;}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size:11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
</style>
</head>
<body >
<h3>第一种方式</h3>
<script>
document.write("<table style='border:1px solid black'>")
for (var i=0;i<1;i++){
document.write("<tr >")
for (var j=0;j<4;j++){
document.write("<td >"+(i*4+j)+"</td>");
}
document.write("</tr>")
}
document.write("</table>");
</script>
<h3>第二种方式</h3>
<script>
(function createTable() {
var ta = document.createElement("table");
ta.setAttribute("style","border:1px solid black");
ta.insertRow();
ta.rows[0].insertCell();
ta.rows[0].cells[0].appendChild(document.createTextNode("0"));
ta.rows[0].insertCell();
ta.rows[0].cells[1].appendChild(document.createTextNode("1"));
ta.rows[0].insertCell();
ta.rows[0].cells[2].appendChild(document.createTextNode("2"));
ta.rows[0].insertCell();
ta.rows[0].cells[3].appendChild(document.createTextNode("3"));
document.body.appendChild(ta);
})()
</script>
</body >
</html>
<head>
<style>
*{margin:0;padding:0;}
table{border-collapse:collapse;}
td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size:11px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
</style>
</head>
<body >
<h3>第一种方式</h3>
<script>
document.write("<table style='border:1px solid black'>")
for (var i=0;i<1;i++){
document.write("<tr >")
for (var j=0;j<4;j++){
document.write("<td >"+(i*4+j)+"</td>");
}
document.write("</tr>")
}
document.write("</table>");
</script>
<h3>第二种方式</h3>
<script>
(function createTable() {
var ta = document.createElement("table");
ta.setAttribute("style","border:1px solid black");
ta.insertRow();
ta.rows[0].insertCell();
ta.rows[0].cells[0].appendChild(document.createTextNode("0"));
ta.rows[0].insertCell();
ta.rows[0].cells[1].appendChild(document.createTextNode("1"));
ta.rows[0].insertCell();
ta.rows[0].cells[2].appendChild(document.createTextNode("2"));
ta.rows[0].insertCell();
ta.rows[0].cells[3].appendChild(document.createTextNode("3"));
document.body.appendChild(ta);
})()
</script>
</body >
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询