How do I clear/reset the selected dates on the jQuery UI Datepicker calendar?

后端 未结 16 1587
感情败类
感情败类 2020-12-02 07:19

How do I reset the datepicker calendar values?.. The min and max date restrictions?

The problem is that when I clear the dates (by deleting the textbox values), th

相关标签:
16条回答
  • 2020-12-02 07:41

    I was trying to accomplish this very thing, that is, empty the datepicker so that filters entered by the user could be removed. Googling a bit I found this sweet piece of code:

    You can add the clear feature even on read only fields. Just add the following code to your datepicker:

    }).keyup(function(e) {
        if(e.keyCode == 8 || e.keyCode == 46) {
            $.datepicker._clearDate(this);
        }
    });
    

    People will be able to highlight (even Read Only fields) and then use backspace or delete key to remove the date using _clearDate function.

    Source

    0 讨论(0)
  • 2020-12-02 07:43
    $('.date').datepicker('setDate', null);
    
    0 讨论(0)
  • 2020-12-02 07:43

    Reset the max date attributes on your datepicker when you click clear.

    From jquery website

    Get or set the maxDate option, after init.
    
        //getter
        var maxDate = $( ".selector" ).datepicker( "option", "maxDate" );
        //setter
        $( ".selector" ).datepicker( "option", "maxDate", '+1m +1w' );
    
    0 讨论(0)
  • 2020-12-02 07:45

    you just need to set the options again to null:

    dates.datepicker( "option" , {
        minDate: null,
        maxDate: null} );
    

    I've changed your jsfiddle: http://jsfiddle.net/tF5MH/9/

    0 讨论(0)
  • 2020-12-02 07:48

    Did you try:

    $('selector').datepicker('setDate', null);
    

    That should work according to the API documentation

    0 讨论(0)
  • 2020-12-02 07:55

    In Firefox it does job for me in form (programmatically), where datepicker control is disabled by default:

    $("#txtDat2").prop('disabled', false); //temporary enable controls<br>
    $("#txtDat2").val("YYYY-MM-DD"); //reset date to dd.mm.yyyyy
    $("#txtDat2").prop('disabled', true); //back to default state
    
    0 讨论(0)
提交回复
热议问题