sol*_*411 1 javascript php ajax jquery jquery-datatables
我已经四处寻找,并且找到了一些对我有用的解决方案.我有一个带ID的表对象.我正在使用JQuery来获取被点击对象上的ID,并希望将其传递给我的数据源,但我无法做到.有人可以帮我吗?
HTML:
<a href="#" data-toggle="modal" data-target="#clusterpulse" id="cluster1">cluster1</a>
Run Code Online (Sandbox Code Playgroud)
JavaScript的:
<script>
$("table").delegate("a", "click", function() {
id2=$(this).attr('id');
});
$('#cluster_pulse_table').dataTable( {
"bprocessing": true,
"bserverSide": true,
"sAjaxSource": "../scripts/cluster_pulse.php?val=" + id2,
} );
</script>
Run Code Online (Sandbox Code Playgroud)
那么你可以改变代表
$("table").on("click", "a", function() {
var id2 = $(this).attr('id');
$('#cluster_pulse_table').dataTable( {
"bprocessing": true,
"bserverSide": true,
"sAjaxSource": "../scripts/cluster_pulse.php?val=" + id2,
});
});
Run Code Online (Sandbox Code Playgroud)
您需要在拥有id2值后调用dataTable.正如你所拥有的那样,没有它就调用了dataTable,因此可能是错误的一个地方.