0

我正在构建 Monthpicker。如何在 datepicker 中进行 ajax 调用?

$(function () {
    $('#datepicker').datepicker({
        minDate: new Date('2013'),
        maxDate: new Date(),
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm",
        onClose: function () {
            $.ajax({
                url: Routing.generate('ajax_table', $this)
            })
        }
    });
}); 

如何传递选定的值onClose?我想在 ajax 调用后渲染一个表格。我正在使用 fos_routing.js。

4

2 回答 2

1

你可以这样写:

$(function () {
    $('#datepicker').datepicker({
        minDate: new Date('2013'),
        maxDate: new Date(),
        changeMonth: true,
        changeYear: true,
        dateFormat: "yy-mm",
        onClose: function (selectedDate) {
            $.ajax({
                url: Routing.generate('ajax_table', {selectedDate: selectedDate})
            })
        }
    });
}); 
于 2018-07-11T07:52:53.923 回答
1

根据http://api.jqueryui.com/datepicker/#option-onClose,Jquery UI DatePicker onClose 事件有 2 个参数。dateText 和 datepicker 实例。

您可以使用 dateText 进行 ajax 调用。我希望这将有所帮助。

于 2018-07-11T07:56:11.743 回答