如何单击行 table 并提醒特定单元格值

How to click row table and alert specific cell value

我有下面这个脚本,我正在寻找的是单击任何行并提醒 "DT_rowID" 单元格值。目前错误消息是:Uncaught ReferenceError: table is not defined

$(document).ready(function() {

    $("body").append('<table cellpadding="0" cellspacing="0" border="0" class="display" id="example"><tbody></tbody></table>');
    var string_id = "http://127.0.0.1:8080/get_data_datatable.php?q=";

    $.ajax({
        url: 'http://127.0.0.1:8080/search.php?q=exosome',

        dataType: 'json',
        type: 'get',
        async: true,
        success: function(data) {


            jQuery.each(data.ids, function(i, val) {
                string_id = string_id + val + ",";
            });

            var table = $('#example').dataTable({

                "ajax": string_id,
                "columns": [{
                    "title": "Product name",
                    "data": "product_name"
                }, {
                    "title": "Quantity",
                    "data": "product_quantity"
                }, {
                    "title": "Price",
                    "data": "price_sell"
                }, {
                    "title": "Currency",
                    "data": "currency_sell"
                }, {
                    "title": "Category",
                    "data": "category"
                }, {
                    "title": "Supplier",
                    "data": "supplier_id"
                }, {
                    "title": "DT_rowID",
                    "data": "product_version_id",
                    "bVisible": false
                }]
            });

        }
    });


    $("#example").css('cursor', 'hand');
    $('#example').on('click', 'tr', function() {
        alert(table.cell(this).data());
    });

});

只要该列仍然是 table 中的最后一列,这就会起作用:

// Added 'tbody' to prevent alert from firing when header row is clicked
$('#example tbody').on('click', 'tr', function() {
    // $(this) is the <tr> element the user clicked
    // td:last finds the last cell within that <tr>
    alert($(this).find('td:last').text());
});

jsFiddle: http://jsfiddle.net/th708qf9/1/