sil*_*ntw 4 jquery html-table jquery-plugins
加载页面时,如果单击某一行,它将记录到控制台clicked.
但是,如果您对表进行排序(单击表标题),tr如果您尝试单击行,则单击事件on 不会被触发.
我正在使用这个插件:tablefixedheader
jQuery的
$(document).ready(function(){
$("table.ex").fixheadertable({
caption : 'Tarefas Disponíveis',
showhide : false,
height : '265',
zebra : true,
zebraClass : 'ui-state-default',
sortable : true,
sortedColId : 0,
dateFormat : 'Y/m/d',
pager : true,
rowsPerPage : 25,
colratio : [110,150],
minColWidth : 110,
resizeCol : true
});
// problem with this click
// The event isn't triggered:
$("table.ex tr").click(function(){
console.log('clicked');
});
});
Run Code Online (Sandbox Code Playgroud)
kap*_*apa 12
您应该使用事件委派,因为插件会更改原始tr元素,因此它们会丢失其附加的事件处理程序.处理程序应该附加在表本身上,因为它肯定没有改变.
$("table.ex").on('click', 'tr', function(){
console.log('clicked');
});
Run Code Online (Sandbox Code Playgroud)