第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何在javascript中把函數(shù)的輸入內(nèi)容和結(jié)果動(dòng)態(tài)生成表格?

如何在javascript中把函數(shù)的輸入內(nèi)容和結(jié)果動(dòng)態(tài)生成表格?

慕碼人2483693 2019-02-06 11:07:07
如何在javascript中把函數(shù)的輸入內(nèi)容和結(jié)果動(dòng)態(tài)生成表格?就是輸入兩個(gè)變量,點(diǎn)一個(gè)按鈕,自動(dòng)生成個(gè)表格
查看完整描述

2 回答

?
慕姐8265434

TA貢獻(xiàn)1813條經(jīng)驗(yàn) 獲得超2個(gè)贊

feipigzi 的代碼沒有給機(jī)會(huì)輸入行列數(shù),而且使用的 createElement 和 appendChild。我還是比較贊成使用較規(guī)范的 insertRow 和 insertCell。


1234567891011121314151617181920<script type="text/javascript">window.onload = function() {    document.getElementById("add").onclick = function() {        var rows = parseInt(document.getElementById("rows").value),            cols = parseInt(document.getElementById("cols").value);        if(rows && cols) {            var table = document.createElement("table");            table.border = 1;            for(var r = 0; r < rows; r++) {                var row = table.insertRow(-1);                for(var c = 0; c < cols; c++) {                    var cell = row.insertCell(-1);                    cell.innerHTML = "行" + (r + 1) + "列" + (c + 1);                }            }            document.body.appendChild(table);        }    };};</script>


123<input type="text" size="4" id="rows" value="" /> 行<input type="text" size="4" id="cols" value="" /> 列<input type="button" id="add" value="生成表格" />


查看完整回答
反對(duì) 回復(fù) 2019-03-14
?
交互式愛情

TA貢獻(xiàn)1712條經(jīng)驗(yàn) 獲得超3個(gè)贊

你說的表格是指html中的表格么?

<input type="text" id="input"/>
<input id="goBtn" type="button" value="GO"/>
<script>
document.getElementById('goBtn').onclick = function () {
var value = document.getElementById('input').value;
if(!value) return;
var table = document.createElement('table');
table.setAttribute("border", '1px');
document.body.appendChild(table);
for(var i = 0; i < 3; i++) {
var row = document.createElement('tr');
for(var k = 0; k < 4; k++) {
var cell = document.createElement('td');
cell.appendChild(document.createTextNode(value));
row.appendChild(cell);
}
table.appendChild(row);
}
};
</script>



查看完整回答
反對(duì) 回復(fù) 2019-03-14
  • 2 回答
  • 0 關(guān)注
  • 1155 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)