我正在使用数据表,并且我选择了多行,我想对多行执行删除操作。例如,我选择了第 2、3 和 4 行,所以我希望同时删除所有 3 行。
<script>
var oTable;
var giRedraw = false;
$(document).ready(function() {
/* Add a click handler to the rows - this could be used as a callback */
$('#example tr').click( function() {
if ( $(this).hasClass('row_selected') )
$(this).removeClass('row_selected');
else
$(this).addClass('row_selected');
} );
/* Add a click handler for the delete row */
$('#delete').click( function() {
var anSelected = fnGetSelected( oTable );
oTable.fnDeleteRow( anSelected[0] );
} );
/* Init the table */
oTable = $('#example').dataTable( );
} );
function fnGetSelected( oTableLocal )
{
var aReturn = new Array();
var aTrs = oTableLocal.fnGetNodes();
for ( var i=0 ; i<aTrs.length ; i++ )
{
if ( $(aTrs[i]).hasClass('row_selected') )
{
aReturn.push( aTrs[i] );
}
}
return aReturn;
}
</script>
通过此脚本一次仅删除 1 行。