gpt4 book ai didi

javascript - 如何在JS函数内将日期(如输入类型日期)添加到td表中?

转载 作者:行者123 更新时间:2023-11-28 16:48:40 25 4
gpt4 key购买 nike

对于这个例子

  $("#add").click(function () {
var html = "<tr>";
html += '<td contenteditable id="data1"></td>';
html += '<td contenteditable id="data2"></td>';
html += '<td contenteditable id="data3"></td>';
html += '<td contenteditable id="data4"></td>';
html += '<td contenteditable id="data5"></td>';
html += '<td contenteditable id="data6"></td>';
html += '<td contenteditable id="data7"></td>';
html += '<td contenteditable id="data8"></td>';
html += '<td contenteditable id="data9"></td>';
html +=
'<td><button type="button" name="insert" id="insert" class="btn btn-success btn-xs">Insert</button></td>';
html += "</tr>";
$("#user_data tbody").prepend(html);
});

如果您能在这方面帮助我,我将不胜感激

最佳答案

为什么以下内容对您不起作用?

const tableBody = document.getElementById("table-body");

const amountOfInputs = 3;

function generateRow() {
let generatedHtmlBody = "<tr>";
for (let i = 1; i <= amountOfInputs; i++) {
generatedHtmlBody += `<td><input id="input-${i}" type="date" /></td>`
}
generatedHtmlBody += `<td><input type="submit" value="submit" /></td></tr>`;
return generatedHtmlBody;
}

function addRow() {
tableBody.innerHTML += generateRow();
}

addRow();
<button onclick="addRow()">Add row</button>
<table>
<thead>
<tr id="table-header-first-row">
<th>Table</th>
</tr>
</thead>
<tbody id="table-body">
</tbody>
</table>

关于javascript - 如何在JS函数内将日期(如输入类型日期)添加到td表中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60224044/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com