Date Range Picker how to fire an event on entering a date

前端 未结 2 1647
余生分开走
余生分开走 2020-12-15 14:03

I\'m using Dan Grossman\'s daterangepicker.

http://www.dangrossman.info/2012/08/20/a-date-range-picker-for-twitter-bootstrap/

Which is initialised in my we

相关标签:
2条回答
  • 2020-12-15 14:19

    this section is the callback function:

    function(start, end) {
        $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
    }
    

    you can add any code you want in this function to execute when a user selects a date. you could even define a callback function yourself and pass it to the daterange picker method.

    example:

    function myCallback(start, end) {
        $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        alert('hello world'); //etc, your code here
    }
    // attach daterangepicker plugin
    $('#dateRange').daterangepicker(options, myCallback);
    

    you also could even define your own custom event handler and trigger it in the callback as well.

    example

    $(document).on('myCustomEvent', function () {
        // your code here
    });
    
    $('#dateRange').daterangepicker({
    // .. //
    function(start, end) {
        $('#dateRange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
        $(document).trigger('myCustomEvent');
    });
    
    0 讨论(0)
  • 2020-12-15 14:30

    From daterangepicker.com:

    $('#daterange').on('apply.daterangepicker', function(ev, picker) {
        alert ('hello');
    });
    
    0 讨论(0)
提交回复
热议问题