87,910
社区成员
发帖
与我相关
我的任务
分享
#div_table {
height: 300px;
}
#div_table table {
width: 100%;
empty-cells: show;
border: 1px green solid;
border-collapse: collapse;
}
#div_table table tr {
height: 30px;
}
#div_table table tr td {
border: 1px green solid;
}
<input type="button" value="生成表格" onclick="createTable();" />
<div id="div_table"></div>
<script src="../../Scripts/jquery-1.9.1.min.js"></script>
var r = document.getElementById('r'),
c = document.getElementById('c');
for (var i = 1; i < 11; i++) {
$('<option value="' + i + '">' + i + '</option>').appendTo(r);
$('<option value="' + i + '">' + i + '</option>').appendTo(c);
}
function createTable() {
var table = '<table>';
for (var i = 0; i < r.value; i++) {
table += '<tr>';
for (var j = 0; j < c.value; j++) {
table += '<td></td>';
}
table += '</tr>';
}
table += '</table>';
$('#div_table').html(table);
}