我使用插件https://datatables.net/ 我想在aLengthMenu上添加onclick并在此处显示所选的值是我的代码:
$(document).ready(function() {
var oTable = $('# Table_id').DataTable({
'iDisplayLength': '50',
"aLengthMenu": [ [20, 50, 100, 200], [20, 50, 100, 200] ]
});
var oSettings = oTable.fnSettings();
var x = oSettings._iDisplayLength; });
答案 0 :(得分:1)
您需要委派点击事件
<强> HTML 强>
<table id="dataTable">...</table>
<强> JS 强>
$(function() {
var oTable = $('#dataTable').DataTable({
'iDisplayLength': '50',
"aLengthMenu": [
[20, 50, 100, 200],
[20, 50, 100, 200]
]
});
var oSettings = oTable.fnSettings();
var x = oSettings._iDisplayLength;
$(document).on("change", ".dataTables_length select", function(){
var selectedVal = $(this).val();
alert(selectedVal);
});
});
<强> FIDDLE 强>