繁体   English   中英

当我单击该行的更新按钮时,如何从jquery数据表中获取文本框值

[英]How to get textbox value from jquery datatables when I click the update button of that row

首先,首先加载数据表,然后更新数量,然后单击更新按钮。 我想获取更新的数量文本框值。

 $('#dataList').dataTable({ 
    "ajax": url + "Sales/SalesTempList",
    "columns": [
        { "data": "Barcode" },
        { "data": "ProdcutDescription" },
        { "data": "RPU" },
        {
            "mData": null,
            "bSortable": false,
            "mRender": function (data, type, full) {
                return '<input type="text" id="' + data.Barcode + '" value="' + data.Sqty + '" class="form-control" />';
            }
        },
        { "data": "Total" },
        {
            "mData": null,
            "bSortable": false,
            "mRender": function (data, type, full) {
                return '<button type="button" onclick="LoadForUpdate(\'' + data.TempId + '\');" class="btn btn-xs btn-info"><i class="fa fa-edit"></i></button>' +
                '&nbsp;&nbsp; <button type="button" onclick="LoadForDelete(\'' + data.TempId + '\');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>';
            }
        }
    ]
});


 function LoadForUpdate(parameters) {
  // need the textbox cell value of edited row when I click the update button of this row
 }

您所需要的只是在单击button时“查找” input ,因此您只需要this关键字添加到onclick函数即可:

onclick="LoadForUpdate(this/* add here */, \'' + data.TempId + '\');

因此,在功能LoadForUpdate您将获得按钮的实例。 然后你“走出去”,以他的tr父母找到输入。

  $('#dataList').dataTable({ "ajax": url + "Sales/SalesTempList", "columns": [ { "data": "Barcode" }, { "data": "ProdcutDescription" }, { "data": "RPU" }, { "mData": null, "bSortable": false, "mRender": function (data, type, full) { return '<input type="text" id="' + data.Barcode + '" value="' + data.Sqty + '" class="form-control" />'; } }, { "data": "Total" }, { "mData": null, "bSortable": false, "mRender": function (data, type, full) { return '<button type="button" onclick="LoadForUpdate(this, \\'' + data.TempId + '\\');" class="btn btn-xs btn-info"><i class="fa fa-edit"></i></button>' + '&nbsp;&nbsp; <button type="button" onclick="LoadForDelete(\\'' + data.TempId + '\\');" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i></button>'; } } ] }); function LoadForUpdate(btn, parameters) { var val = $(btn).parents('tr').first().find('input').val(); } 

暂无
暂无

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

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