Remove Datepicker Function dynamically

后端 未结 6 1541
时光取名叫无心
时光取名叫无心 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:21

    This is the solution I use. It has more lines but it will only create the datepicker once.

    $('#txtSearch').datepicker({
        constrainInput:false,
        beforeShow: function(){
            var t = $('#ddlSearchType').val();
            if( ['Required Date', 'Submitted Date'].indexOf(t) ) {
                $('#txtSearch').prop('readonly', false);
                return false;
            }
            else $('#txtSearch').prop('readonly', true);
        }
    });
    

    The datepicker will not show unless the value of ddlSearchType is either "Required Date" or "Submitted Date"

提交回复
热议问题