<script>
function CreateTable(row, col, width, height) {
this.row = row;
this.col = col;
this.width = width;
this.height = height;
}
var _box = document.getElementById('box');
CreateTable.prototype.outTable = function() {
var _row = this.row;
var _col = this.col;
var _width = this.width;
var _height = this.height;
var html = '<table border="1" cellspacing="0" width="' + _width + '" height="' + _height + '">'
for (let i = 1; i <= _row; i++) {
html += '<tr>';
for (let j = 1; j < _col; j++) {
html += '<td></td>';
}
html += '</tr>';
}
_box.innerHTML = html;
}
var table01 = new CreateTable(4, 4, 600, 400);
table01.outTable();
</script>
使用js构造函数创建一个自定义对象,通过自定义对象生成指定行数、列数、宽度和高度的表格。
最新推荐文章于 2022-10-20 18:20:35 发布