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