1 回答
TA贡献1893条经验 获得超10个赞
您可以通过使用然后迭代该集合或按索引访问特定单元格来简化对元素的访问<td>clone.cells
function copy_checklist(row_id, poNum) {
var row = document.getElementById("item"); //get table row
var table = document.getElementById("checklist");
var clone = row.cloneNode(true);
var cells = clone.cells;
clone.id = row_id;
cells[0].innerHTML = poNum
// OR
//Array.from(cells).forEach((cell, index) => cell.innerHTML = poNum);
table.appendChild(clone);
}
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head>
<meta charset='utf-8' />
<title></title>
<style>
tr {
height: 40px;
}
</style>
</head>
<body onLoad="copy_checklist('1', 'po-202')">
<table border='0' cellspacing='0' cellpadding='0' style='font-family: Arial; font-size: 12px;'>
<tbody id="checklist">
<tr id="item">
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-top:0px;font-family:Arial;font-size:12px;text-align:center!important;word-break: break-word;width:78px'>
<div id="poNum">po2</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:77px'>
<div id="skuNum">sku</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:85px'>
<div id="itemDesc">desc</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:58px'>
<div id="lotId">WK 14</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:65px'>
<div id="lotSize">1</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:50px'>
<div id="sampleSize">2</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:50px'>
<div id="criticalDefects">3</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:50px'>
<div id="majorDefects">4</div>
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;word-break: break-word;width:50px'>
<div id="minorDefects">5</div>
</td>
<td style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;width:350px;'></td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;width:40px;word-break: break-word;width:50px'></td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;width:40px;word-break: break-word;width:50px'>
See Pic
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;width:40px;word-break: break-word;width:50px'>
Ok
</td>
<td nowrap='nowrap' style='padding:5px 2px;border:1px solid #000000;border-left:0px;border-top:0px;font-family:Arial;font-size:12px;width:40px;word-break: break-word;width:50px'>
%
</td>
</tr>
</tbody>
</table>
添加回答
举报