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

后端 未结 16 1660
感情败类
感情败类 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:36

    A modified version of Leniel Macaferi's solution to account for the backspace key being a "page back" shortcut in IE8 when a text field does not have focus (which appears to be the case when datepicker is open).

    It also uses val() to clear the field since _clearDate(this) did not work for me.

    $("#clearDates").datepicker().keyup(function (e) {
        // allow delete key (46) to clear the field
        if (e.keyCode == 46)
            $(this).val("");
    
        // backspace key (8) causes 'page back' in IE8 when text field
        // does not have focus, Bad IE!!
        if (e.keyCode == 8)
            e.stopPropagation();
    });
    

提交回复
热议问题