【问题标题】:What is the better way to add new row in a table in mvc4?在 mvc4 的表中添加新行的更好方法是什么?
【发布时间】:2014-03-27 11:54:12
【问题描述】:

点击 Addrow 按钮后如何添加新行。这可以用jquery添加新行吗?

<td>
      <input type="button" id="btnnew" value="AddRow" />
      </td>

【问题讨论】:

标签: jquery asp.net-mvc-4 c#-4.0 datatable


【解决方案1】:

创建新行并将其附加到父表

$("#btnnew").click(function (){
        $(this).parents("table").append("<tr><td>test</td></tr>");
    });

【讨论】:

    【解决方案2】:

    新建一个TR,根据表id添加到表中

    $(document).ready(function(){
    $("#btnnew").bind("click",function(){
    var tr=$("<tr>");
    $("table tbody").append(tr);
    });
    
    });
    

    【讨论】:

      【解决方案3】:

      您必须在按钮的客户端单击事件上调用此 jquery 并使用 jQuery 在表中添加新行:

      $("#btnnew").click(function (){
          $('#myTable > tbody:last').append('<tr>...</tr><tr>...</tr>');
      }
      

      【讨论】:

      • 您无法从给出的示例中判断这是否可行
      猜你喜欢
      • 2018-02-19
      • 1970-01-01
      • 2023-04-02
      • 1970-01-01
      • 2021-08-18
      • 2014-05-03
      • 1970-01-01
      • 2017-01-22
      • 2017-03-23
      相关资源
      最近更新 更多