[英]How do you add a row to a Javascript table with a cell containing the datepicker function from jQuery?
I have this javascript function: 我有这个javascript函数:
function addItem(tableID){
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var cell1 = row.insertCell(0);
var element1 = document.createElement("input");
element1.type = "checkbox";
element1.name="checkbox[]";
cell1.appendChild(element1);
var cell2 = row.insertCell(1);
var element2 = document.createElement("input");
element2.type = "text";
element2.name = "textbox[]";
cell2.appendChild(element2);
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
// *****I DO NOT KNOW WHAT GOES HERE*****
cell3.appendChild(element3);
}
I also have an HTML file that where it looks like this: 我还有一个HTML文件,看起来像这样:
<header>
<div id="header-left">
<input type="checkbox" id="select-all"></input>
<label for="select-all" id="select-all-tag"> Select All </label>
</div>
<h1> TODO </h1>
<div id="header-right">
<button id="sort-by">Sort By</button>
<button id="add-new" onclick="addItem('todoTable')">Add</button>
</div>
</header>
<table id="todoTable" border="1">
<tr>
<td><input type="checkbox" name="checkbox"/></td>
<td><input type="text" /></td>
<script>
$(function() {
$(".date-picker").datepicker();
});
</script>
<td><input type="text" name="date[]" class="date-picker datepicker"></td>
</tr>
</table>
The HTML file creates the sort of row that I want. HTML文件会创建所需的行。 For the JavaScript, I am trying to add a row with a datepicker in the third cell, but I do not know how.
对于JavaScript,我试图在第三个单元格中添加带有日期选择器的行,但我不知道如何。 So, how do I have a datepicker show in the third cell in JavaScript?
那么,如何在JavaScript的第三个单元格中显示日期选择器? Please let me know if you need clarification.
如果您需要澄清,请告诉我。
So long as you have the appropriate scripts included, this should suffice: 只要您包含适当的脚本,这就足够了:
var cell3 = row.insertCell(2);
var element3 = document.createElement("input");
$(element3).datepicker();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.