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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 querySelectorAll 方法并在單擊時創(chuàng)建表

使用 querySelectorAll 方法并在單擊時創(chuàng)建表

狐的傳說 2023-09-21 17:08:36
我的教授指派我執(zhí)行以下操作: 創(chuàng)建一個 HTML 文件以使用 JavaScript 實現(xiàn)文檔對象模型的概念。使用 getElementById 方法并寫入元素使用 getElementsTagName 方法并更改顏色并向元素添加邊框使用 getElementsByClassName 方法,對于具有相同類名的段落和標(biāo)題,更改對齊方式使用 querySelectorAll 方法并在單擊時創(chuàng)建表但是我不知道如何實現(xiàn)最后一個......我可以幫忙嗎?function msg4(){    var table = querySelectorAll("table");    //alert("Testing...");    var row = table.insertRow(0);    var cell1 = row.insertCell(0);    var cell2 = row.insertCell(1);    cell1.innerHTML = "NEW CELL1";    cell2.innerHTML = "NEW CELL2";}
查看完整描述

1 回答

?
弒天下

TA貢獻1818條經(jīng)驗 獲得超8個贊

您可以使用下面的代碼使用對象創(chuàng)建表


let mountains = [

  { name: "Monte Falco", height: 1658, place: "Parco Foreste Casentinesi" },

  { name: "Monte Falterona", height: 1654, place: "Parco Foreste Casentinesi" },

  { name: "Poggio Scali", height: 1520, place: "Parco Foreste Casentinesi" },

  { name: "Pratomagno", height: 1592, place: "Parco Foreste Casentinesi" },

  { name: "Monte Amiata", height: 1738, place: "Siena" }

];


function generateTableHead(table, data) {

  let thead = table.createTHead();

  let row = thead.insertRow();

  for (let key of data) {

    let th = document.createElement("th");

    let text = document.createTextNode(key);

    th.appendChild(text);

    row.appendChild(th);

  }

}


function generateTable(table, data) {

  for (let element of data) {

    let row = table.insertRow();

    for (key in element) {

      let cell = row.insertCell();

      let text = document.createTextNode(element[key]);

      cell.appendChild(text);

    }

  }

}


let table = document.querySelector("table");

let data = Object.keys(mountains[0]);

generateTableHead(table, data);

generateTable(table, mountains);


查看完整回答
反對 回復(fù) 2023-09-21
  • 1 回答
  • 0 關(guān)注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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