我在互联网上搜索了很多,并没有找到解决我问题的方法。
我正在使用 AJAX、PHP 和数据表。连接工作正常。我可以在我的数据表中显示记录。
我想这样做不起作用的是,当鼠标悬停在每一行上时,它会“点亮”并将鼠标移回正常状态。
据我设法发现,发生在我身上的是事件没有检测到行。也就是我使用的代码如下...
$("#tabla tbody tr").each(function(){
$(this).mouseover(function(){
$(this).addClass("ui-state-hover");
}).mouseout(function(){
$(this).removeClass("ui-state-hover");
});
});
html代码:
<table id="tabla">
<thead>
<tr>
<th>Id</th>
<th>Titulo</th>
<th>Subtitulo</th>
<th>Fecha</th>
<th>Acceder</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
如果我手动向页面添加一行,则鼠标悬停示例:
<table id="tabla"> <thead> <tr> <th>Id</th> <th>Titulo</th> <th>Subtitulo</th> <th>Fecha</th> <th>Acceder</th> </tr> </thead> <tbody> <tr > <td>4</td> <td>Titulo</td> <td>Subtitulo</td> <td>2013-09-11 00:00:00</td> <td>4</td> </tr> </tbody> </table>
问题是当通过 AJAX 函数插入行时我不工作。
AJAX 代码:
$.ajax({
url:'./listahistorias_proceso.php',
type:'post',
data:{ tag: 'getData'},
dataType: 'json',
success: function(data){
if(data.success){
$.each(data, function(index,record){
if($.isNumeric(index)){
var row = $("<tr />");
$("<td />").text(record.idhistoria).appendTo(row);
$("<td />").text(record.titulo).appendTo(row);
$("<td />").text(record.subtitulo).appendTo(row);
$("<td />").text(record.fecha).appendTo(row);
$("<td />").text(record.acceder).appendTo(row);
$("<tr>");
row.appendTo('table tbody');
}
})
}
oTable = $('table').dataTable({
"bjQueryUI": true,
"sPaginationType": "full_numbers",
"oLanguage": {
"sLengthMenu": "Mostrar _MENU_ filas por pagina",
"sZeroRecords": "Datos no encontrados",
"sInfo": "Mostrando _START_ a _END_ de _TOTAL_ filas",
"sInfoEmpty": "Sin entradas para mostrar",
"sInfoFiltered": "",
"sSearch": "Buscar",
"sProcessing": "Buscando...",
"sLoadingRecords": "Por favor espere - Cargando...",
"sEmptyTable": "No se obtuvieron datos",
"oPaginate": {
"sFirst": "Primera",
"sPrevious": "Anterior",
"sNext": "Siguiente",
"sLast": "Ultima"
}
},
"aoColumns":[
{'sname':'id', 'sType':'numeric', 'bVisible':true},
{'sName':'Titulo', 'sType':'string','bVisible':true},
{'sName':'Subtitulo', 'sType':'string','bVisible':true},
{'sName':'Fecha', 'sType':'date','bVisible':true},
{'sName':'Acceder', 'sType':'numeric','bVisible':true}
],
"oTableTools": {
"sRowSelect": "single",
"fnRowSelected": function( node ) {
alert("Clicked");
}
}
})
},
error: function(jqXHR, textStatus, errorThrown){
alert("error ==>" + jqXHR.responseText);
alert("error ==>" + jqXHR.textStatus);
alert("excepcion ==>" + errorThrown);
}
}); //ajax
注意:我绑定了 .live()、.on()、.click() 并且不起作用。
同样,我认为问题在于它没有检测到由 ajax 插入的行。
从已经非常感谢了。我希望我很清楚。我等待你的意见。
再次感谢你。问候。