为Datatables网格中的所有行添加JavaScript函数

为Datatables网格中的所有行添加JavaScript函数,javascript,datatable,Javascript,Datatable,$(文档).ready(函数(){ $(“#示例”).DataTable(); }); 函数do_ok(){ document.getElementById(“a3”).checked=true; } 函数do_error(){ document.getElementById(“a12”).checked=true; } 产品 包括 A01 A02 A03 A04 A05 A06 A07 A08 A09 A10 A11 A12 单击我(确定) 单击我(第12行) 此代码可能会有所帮助,但您需要

$(文档).ready(函数(){
$(“#示例”).DataTable();
});
函数do_ok(){
document.getElementById(“a3”).checked=true;
}
函数do_error(){
document.getElementById(“a12”).checked=true;
}

产品
包括
A01
A02
A03
A04
A05
A06
A07
A08
A09
A10
A11
A12
单击我(确定)
单击我(第12行)

此代码可能会有所帮助,但您需要使其适合您的解决方案:

$(document).ready(function() {

  // Common function to update checkboxes
    function updateCheckBox(){

    // Use jQuery to set property so that
    // on not found element it fails silenty
    // and continue to next
    $("#a3").prop('checked',true);
    $("#a12").prop('checked',true)
  }

  // Initialize DataTable with event on 'draw' to
  // update checkboxes
  $('#example').DataTable().on('draw.dt', updateCheckBox);

  // Initial checkbox status
  updateCheckBox();

});

您能切换到a12所在的页面,然后尝试检查=真吗@John@ShubhamSingla我当然可以。然而,我实际有5000多行,我不希望用户显示第4000行或切换到第4000行页面以选中=true。我认为这些文章概述了使用复选框列的预期数据驱动方式:我认为我离rofl越来越近了。假设函数updateCheckBox带有参数,您能帮我吗?我刚刚更新了你的JSFIDLE。谢谢你的帮助!我猜你希望按钮正常工作,成功地救了我一天;)谢谢,请在申请生产前好好测试一下