简体   繁体   English

如何使用包含jQuery中datepicker函数的单元格向Javascript表添加行?

[英]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.

相关问题 jQuery如何将表格单元格添加到表格行 - JQuery How to add table cell to a table row 如何在javascript中将输入字段动态添加到我的html表格行内的单元格中? - How do I dynamically add an input field into a cell inside my html table row in javascript? 如何将来自不同功能的多个 arguments 添加到一个包含所有参数的 function 中? - How do you add multiple arguments from different functions into one function containing all the parameters? 如何使用jquery从表行中的onclick中调用javascript函数来设置表行的突出显示? - How to set the highlight of a table row with jquery from a javascript function call from an onclick in the table row? 将表格单元格添加到现有表格行jQuery - Add table cell to existing table row, jQuery 功能JavaScript在表格中添加行 - Function JavaScript to add row in a table 使用Jquery,如何使用从网址返回的竞赛来更新HTML表的行? - Using Jquery, how do you update a row of an HTML table with the contests returned from a url? 如何根据行中另一个单元格的内容修改HTML表行的内容? - How do you modify the contents of an HTML table row based on the contents of another cell in the row? 您如何将jQuery函数放入javascript函数中? - How do you put a jquery function inside a javascript function? 如何将 Fontawesome 图标添加到 JavaScript 函数中的按钮 - How do you add a Fontawesome icon to a button in a JavaScript function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM