当我从选择字段中选择一个选项时,如何执行此daterangepicker()函数:
最终这就是我想要做的事情:
===== UPDATE(我删除了我原来的测试代码,它太模糊了)==========
这是我的实际代码:
<select id="topSellingMaxAmount" style="margin-top:7px;">
<option value="10">10</option>
<option value="25">25</option>
<option value="50" selected>50</option>
<option value="100">100</option>
<option value="200">200</option>
<option value="300">300</option>
<option value="400">400</option>
<option value="500">500</option>
</select>
function initDPicker(){
$('#reportrange').daterangepicker({
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract('days', 1), moment().subtract('days', 1)],
'Last 7 Days': [moment().subtract('days', 6), moment()],
'Last 30 Days': [moment().subtract('days', 29), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract('month', 1).startOf('month'), moment().subtract('month', 1).endOf('month')]
},
startDate: moment().subtract('days', 29),
endDate: moment()
},
function(start, end) {
$("#progressBar").show();
var url = $("input#dashboardAjaxUrl").val();
var startDate = start.format('M-D-YYYY');
var endDate = end.format('M-D-YYYY');
var topSellingMaxAmount = $("#topSellingMaxAmount").val();
$.ajax({
url: url,
dataType: "json",
type: "POST",
data: {
startDate: startDate,
endDate: endDate,
maxAmount: topSellingMaxAmount
},
success: function( data ) {
var oTable = $("#datatableX").dataTable();
oTable.fnClearTable();
for(var i = 0; i <= data.iTotalRecords; i++) {
oTable.fnAddData([
data.aaData[i][0],
data.aaData[i][1],
data.aaData[i][2],
data.aaData[i][3],
data.aaData[i][4],
data.aaData[i][5]
]);
}
}, complete: function(){
$("#progressBar").hide();
}
});
$('#reportrange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
);
}
$("#topSellingMaxAmount").on("change", function(){
// something here to execute the datepicker to actually fire....
});
initDPicker();
感谢您的帮助!
答案 0 :(得分:0)
$('#topSellingMaxAmount').on('change', function() {
$('#reportrange').daterangepicker({options in here});
alert( 'popup' );
});
当我相信选择时,这将调用datepicker弹出窗口。