我想在点击特定行后执行一些操作。我遵循API,这是我最终得到的但是点击事件不起作用。
$(document).ready(function() {
table = $('#employees').dataTable( {
"bJQueryUI": true,
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "show_employee_processor.php",
"aoColumns": [
{ "sTitle": "Empoyee ID" },
{ "sTitle": "Last Name" },
{ "sTitle": "First Name" },
{ "sTitle": "BBan Number" },
]
} );
table.$('tr').click(function() {
var data = table.fnGetData( this );
alert(data);
});
} );
正在绘制数据表但是click事件不起作用。我错过了什么?
答案 0 :(得分:2)
尝试委托活动:
table.on('click','tr',function() {
var data = table.fnGetData( this );
alert(data);
});
或:
$('#employees').on('click','tr',function() {
var data = table.fnGetData( this );
alert(data);
});
答案 1 :(得分:0)
$("#employees tr").click( function( e ) {
if ( $(this).hasClass('row_selected')==false ) {
table .$('tr.row_selected').removeClass('row_selected');
$(this).addClass('row_selected');
var data = table.fnGetData( this );
alert(data);
}
else{
$(this).removeClass('row_selected');
}
});
CSS>
#employees tr.row_selected{
background-color:#B5CCD2;
opacity:0.95;
font-weight:bold;
}