How to add an onclick event on a newly added row (

2019-03-03 21:51发布

问题:

I'm adding rows dynamically using

table.row.add

and I want to, for every row that is added to the table, to also add an onclick event to that row so it links to a URL.

So, how do I refer to the row that has just been added to add this event?

回答1:

You can add an onclick to this event :

 $(document).ready(function() {
 $('#example').DataTable( {
      "createdRow": function ( row, data, index )
       {
           // here
       }
    } );
 } );