如何返回自定义数据表输入值



我有一个带有生成的输入字段和按钮的DataTable。当我单击按钮时,我想要console.log输入字段内的值。有人能帮忙吗?下面是我生成的表:

var productsTable = $('#productsTable').DataTable({
    responsive: true,
    "ajax": {
        "url": "/api/products/",
        "dataSrc": ""
    },
    "columns": [
        { "title": "Product Code", "data": "product_code" },
        { "title": "Supplier", "data": "supplier" },
        { "title": "Category", "data": "category"},
        { "title": "Description", "data": "description"},
        { "title": "Price", "data": "invoice_price"},
        { "title": "Quantity", "defaultContent": "<input class='quantity' type='number'>" },
        { "title": "", "defaultContent": "<button class='btn btn-primary'>Click Me!</button>" },
    ]
   });

下面是我对click事件的尝试:

$("#productsTable tbody").on('click', 'button', function() {
    var quantity = $(this).parents("tr:first").find('.quantity input').val();
    console.log(quantity); // returns undefined
 });

有人能帮忙吗?

提前感谢!

请试试

var quantity = $(this).parents("tr:first").find('.quantity').val();

相关内容

  • 没有找到相关文章

最新更新