<html>
<title></title>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript">
var init = function(r,c) {
var template = "";
for(var i = 0; i < r; i++) {
template += "<tr>";
for(var j = 0; j < c; j++) {
template += "<td>1</td>";
}
template += "</tr>";
}
$("table").append(template);
};
$(function(){
init(4,5);
});
</script>
<body>
<table border="1"></table>
</body>
</html>
方法很多啊
<script language="javascript"> var o = document.body; //创建表格 function createTable(w,h,r,c) { var table = document.createElement("table"); var tbody = document.createElement("tbody"); table.width = w; table.height = h; table.border = 1; for(var i=1;i<=r;i++) { var tr = document.createElement("tr"); for(var j=1;j<=c;j++) { var td = document.createElement("td"); td.innerHTML = i + "" + j; //td.appendChild(document.createTextNode(i + "" + j)); td.style.color = "#FF0000"; tr.appendChild(td); } tbody.appendChild(tr); } table.appendChild(tbody); o.appendChild(table); } createTable(270,270,9,9); </script>