【发布时间】:2018-09-08 05:52:22
【问题描述】:
我想按照下面代码中的方式显示表格,但不显示在屏幕上,代码仅使用 html 和 Javascript
<body id="page">
<center>
<table id="tables" border="1px" cellspacing="50px" style="margin-top:70px" >
<script type="text/javascript">
var row=2;
for(var j=1;j<=2;j++){
$('#tables').append("<tr id='row"+j+"' style='margin-bottom:50px'>");
for(var k=1;k<=5;k++){
$("#row"+j).append("<td id='table"+k+"' class='button' width='150' height='150' onclick='printBill("+k+")' background='images/green.png' align='center'>"+
"<font size='+8'><b>"+k+"</b></font>"+
"<br><font id='clock"+k+"' size='+1'> 0:0:0 </font>"+
"</td>");
}
$('#tables').append("<tr id='row"+j+"' style='margin-bottom:50px'>");
}
</script>
</table>
</center>
</body>
谁能帮忙找出这段代码有什么问题?
【问题讨论】:
-
您的脚本在表对象中可能无济于事(因此可能找不到)...尝试放入 onload 触发函数
-
我发现你的代码在这里运行良好:jsfiddle.net/6332Q你是否包含了 jQuery?
-
offtopic:你可以在桌子上用
margin-left:auto; margin-right:auto;代替。 -
另外,如果你不想过早的精神错乱,你应该只创建一个具有相同 id 的元素 :)
标签: javascript html-table