亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

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

JavaScript 錯誤,無法將單元格添加到表格行

JavaScript 錯誤,無法將單元格添加到表格行

桃花長相依 2023-07-29 15:52:51
這是我的 HTML 代碼:<input type='hidden' id='hiddenRowId' value='0' /><a href='#' onclick='addItem(); return false' class='buttonAdd'>Add Item</a><table id='tb1'>    <tr>        <th>No</th>        <th>Seq</th>        <th>Item Name</th>        <th>Compulsory</th>        <th>Fixed Qty</th>        <th>Qty</th>        <th>Unit Price</th>        <th></th>    </tr></table>這是 JavaScript:function addItem() {    hiddenRowId = document.getElementById('hiddenRowId');    let rowid = parseInt(hiddenRowId.value);    if (isNaN(rowid)) {        rowid = 0;    }    rowid--;    hiddenRowId.value = rowid;    let tb1 = document.getElementById('tb1');    let tr = tb1.insertRow(-1);    tr.id = "tr" + rowid;    let cell1 = tr.insertCell(-1);    let cell2 = tr.insertCell(-1);    let cell3 = tr.insertCell(-1);    let cell4 = tr.insertCell(-1);    let cell5 = tr.insertCell(-1);    let cell6 = tr.insertCell(-1);    let cell7 = tr.insertCell(-1);    let cell8 = tr.insertCell(-1);    cell2.innerHtml = `<input type='text' name='txt_${rowid}_seq' value='' style='width: 40px;' />`;    cell3.innerHtml = `<input type='text' name='txt_${rowid}_name' value='' style='width: 300px;' />`;    cell4.innerHtml = `<input type='checkbox' name='txt_${rowid}_compulsory'  />`;    cell5.innerHtml = `<input type='checkbox' name='txt_${rowid}_fixqty'  />`;    cell6.innerHtml = `<input type='text' name='txt_${rowid}_qty' value='1' style='width 40px;' />`;    cell7.innerHtml = `<input type='text' name='txt_${rowid}_unitprice' value='' style='width: 80px;' />`;    cell8.innerHtml = `<a href='#' onclick='remove(${rowid}); return false;' class='buttonmain'>Delete</a>`;}javascript 不知何故無法正常工作。添加了行,但沒有添加單元格。你知道缺少什么步驟嗎?“添加項目”鏈接按鈕不起作用。https://jsfiddle.net/L09up1rj/有沒有更合適的方法來做到這一點?
查看完整描述

1 回答

?
jeck貓

TA貢獻1909條經驗 獲得超7個贊

將所有 cell.innerHtml 替換為 cell.innerHTML。



查看完整回答
反對 回復 2023-07-29
  • 1 回答
  • 0 關注
  • 146 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號