简体   繁体   English

如何使用jQuery在数据表中添加数据?

[英]How to add data inside datatable using jquery?

I want to do is make a function that add data in my table and have a delete function in action column using jquery. 我想做的是一个函数,该函数在表中添加数据,并使用jquery在action column具有删除功能。

My problem is I'm having trouble putting my input values in the table using jquery. 我的问题是我无法使用jquery将输入值放在表中。

  function Add(){
    $("#myTable tbody").append(
        "<tr>"+
        "<td><input type='text'/></td>"+
        "<td><input type='text'/></td>"+
        "<td><input type='radio'/></td>"+
        "<td><button class='btnDelete>Delete</button></td>"+
        "</tr>");   
        $(".Save").bind("click", Save);     
}; 

If you are using datatable, then use datatable 'fnAddData' function for adding new row instead of jquery append function. 如果您使用的是数据表,请使用数据表'fnAddData'函数添加新行,而不是使用jquery append函数。 Check the following code, 检查以下代码,

    oTable = $('#myTable').dataTable();

     function Add(){

          var data = [
             $('#input1').val(),
             $('#input2').val(),
             $('#input3').val(),
             $('#input4').val()
          ];


          oTable.fnAddData(data);
     };

Here is legacy documentation for version 1.9.x 这是1.9.x版的旧版文档

How to add row for version 1.9.x and below 如何为1.9.x及以下版本添加行

Note: You better start using new version of data table 1.10.x 注意:您最好开始使用新版本的数据表1.10.x

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM