function boardSize(id, btnid)
{
function hitheadr(id,btnid) {
return function () {
console.log(id);
};
}
function createTable(rows, cols, element) {
function getButtonId( ) {
return 'hit'
}
var table = document.createElement('table'),
tr, td, button, i, j,
colors = ["red", "blue", "yellow"];
for (i = 0; i < rows; i++) {
tr = document.createElement('tr');
for (j = 0; j < cols; j++) {
td = document.createElement('td');
button = document.createElement('button');
button.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)];
button.appendChild(document.createTextNode(getButtonId(i, j)));
button.onclick = hitheadr(getButtonId(i, j));
button.id = getButtonId(i, j);
button.onclick = onBtnClick;
// button.innerHTML = 'HIT';
/* document.getElementById(getButtonId(i, j)).onclick = function () {
alert('should ');
};*/
button.id = getButtonId(i, j);
td.appendChild(button);
tr.appendChild(td);
}
table.appendChild(tr);
table.setAttribute("align", "center");
tr.setAttribute("border", "2");
}
element.appendChild(table);
}
createTable(3, 3, document.body);
document.getElementById(btnid).disabled = true;
document.getElementById(btnid).style.backgroundColor = "#00CCFF";
document.getElementById('le').disabled = true;
document.getElementById('se').disabled = true;
}
</tr> </table>
</div>
<div class="content">
<table>
<tr>
<td> <input type="button" class="button" name="st" value= "3*3" id="re" onclick ="boardSize(1,'re')" > </td>
我有一个按钮来显示表格中的表格,但它在表格外显示表格如何在表格中显示 如何在表单中显示按钮的内容帮助我。
答案 0 :(得分:1)
在代码中,您正在创建表作为正文的子表,这就是它出现在表单外部的最后一部分的原因。在createTable函数中,将第三个参数作为要在其中显示表的表单传递。作为createTable(3, 3, document.querySelector('form'))