复选框Click事件在数据表中的第二页不起作用?

时间:2016-12-12 17:28:24

标签: javascript jquery dom checkbox datatables

我有一个数据表并填充了Ajax响应。我在顶部有一个提交按钮,我想处理提交的点击事件, 我在每行输入文本框,下面的代码仅适用于前10行,如果单击数据表中的下一个按钮,则提交($('#createOrderId')。click)事件不起作用。我尝试在fndrawcallback中创建更改事件,但这也无法正常工作。 谁可以帮我这个事。

function showCheckoutResults(obj) {
oTable = $('#checkoutTable').DataTable({
    bDestroy : true,
    "autoWidth": false,
    columnDefs : [ {
        width: "2%", 
        targets : 0,
        className : 'dt-body-center select-checkbox',
        'checkboxes': {
               //'selectRow': true
            }
    },
    {
        "targets": [ 10 ],
        "visible": false
    }
    ],
    select : {
        style : 'multi',
        selector: 'td:first-child'

    },
    order : [ [ 1, 'asc' ] ],
    "fnDrawCallback": function() {
        loadDatePicker();
         $('.commonOrderQty').on('change', function () {
             var dataArr = [];

                var rows_selected =  oTable.column(0).checkboxes.selected();
                if (typeof rows_selected != 'undefined') {
                    $.each(rows_selected, function(index, rowId){
                         dataArr.push(rowId);
                    });
                }
                for(var i=0;i<dataArr.length;i++) {
                    $( "#ordQty" + dataArr[i] ).change(function() {
                        alert($("#ordQty" + dataArr[i]).val);
                        validateOrderQty( dataArr[i]);
                    });
                }
         });
    }

});
oTable.rows().remove().draw();
$.each(obj, function(index, key) {
    var ordrSrchResultData = [];
    var finalLeadTime = calculateLeadTime(key.fopLeadTime);
    var unitPrice = key.quote;
    if(key.um == 'CPC') {
        unitPrice = key.quote/100;
    }
    ordrSrchResultData.push(index);
    ordrSrchResultData.push('<input id="po' + index
                + '" type="text" maxlength="12" class="checkoutText" value="' + key.poNo + '"/>');
    ordrSrchResultData.push('<input id="ordQty' + index
            + '" type="text" class="checkoutText commonOrderQty" value="' + key.orderQty + '"/>');
    ordrSrchResultData.push('<input id="boxQty' + index
            + '" type="text" class="checkoutText" value="' + key.boxQty + '"disabled/>');
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="datePicker' + index
                + '" value="'  + key.dueDate + '" readonly="readonly"/>');          
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="datePicker' + index
                + '" value="'  + finalLeadTime + '" readonly="readonly"/>');
    ordrSrchResultData.push('<input id="partNo' + index
            + '" type="text" class="checkoutText" value="' + key.partNo + '"disabled/>');
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="suppPartNo' + index
                + '" value="' + key.suppPartNo + '" readonly="readonly"/>');
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="extPrice' + index
            + '" value="' + key.extPrice + '" readonly="readonly"/>');
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="customerCd' + index
            + '" value="' + key.customerCd + '" readonly="readonly"/>');
    ordrSrchResultData.push('<input type="text" class="checkoutText" id="quote' + index
            + '" value="' + unitPrice + '" readonly="readonly"/>');
    ordrSrchResultData.push('<input type="hidden" value="'+key.dueDate+'" id="existDatePicker'+index+'"');
    oTable.columns.adjust().draw();
    oTable.row.add(ordrSrchResultData).draw();
    localStorage.setItem('_selectedStartDate', finalLeadTime);
    updateDatepicker(index, finalLeadTime);
    $('#checkoutTable tr:last').attr('id', 't' + index);
    $("#" + 't' + index).removeClass('selected');
    $( "#ordQty" + index ).change(function() {
        validateOrderQty(index);
    });
});}
$('#createOrderId').click(function (){      
    var dataArr = [];
    var rows_selected =  oTable.column(0).checkboxes.selected();
    $.each(rows_selected, function(index, rowId){
      dataArr.push(rowId);
      });       
    var rowsCount = dataArr.length;
    var errMsg = $("#noSelectedDataErrMsg").val();      
    if(rowsCount == 0) {
        jQuery("label[for='ordlabelvalue']").html(errMsg);
        $('#orderErrorModal').modal('show');
        return;
    }
    createOrder(dataArr);
});

1 个答案:

答案 0 :(得分:2)

而不是:

$('#createOrderId').click(function (){

使用此:

 $(document).on('click','#createOrderId',function (){