Remove Datepicker Function dynamically

后端 未结 6 1531
时光取名叫无心
时光取名叫无心 2020-12-03 02:31

I want to remove datepicker function depending on the dropdownlist selected value. I try the following codes, but it still shows the calendar when I put the cursor in the t

6条回答
  •  独厮守ぢ
    2020-12-03 03:17

    You can try the enable/disable methods instead of using the option method:

    $("#txtSearch").datepicker("enable");
    $("#txtSearch").datepicker("disable");
    

    This disables the entire textbox. So may be you can use datepicker.destroy() instead:

    $(document).ready(function() {
        $("#ddlSearchType").change(function() {
            if ($(this).val() == "Required Date" || $(this).val() == "Submitted Date") {
                $("#txtSearch").datepicker();
            }
            else {
                $("#txtSearch").datepicker("destroy");
            }
        }).change();
    });
    

    Demo here.

提交回复
热议问题