简体   繁体   English

使用下拉asp.net启用/禁用datepicker

[英]enable/disable datepicker with dropdown asp.net

i have dropdown for selecting data type of data in a textbox. 我在文本框中选择数据的数据类型的下拉菜单。 dropdown options are like integer, decimal,string,date. 下拉选项类似于整数,十进制,字符串,日期。

everything is working fine except one thing that is am unable to get a datepicker to the text box when dropdown is selected to date. 一切工作正常,但当选择下拉列表时,有一件事情无法使日期选择器进入文本框。

tried something like but failed to achieve 尝试过类似但未能实现的事情

$(function () {
            $(".date1").datepicker({
                changeMonth: true,
                changeYear: true,
                numberOfMonths: 1

            });
        });

$("#<%=ddlDataType.ClientID %>").change(function () {
            if ($('#<%=ddlDataType.ClientID %> option:selected').text().toLowerCase() == "date") {
                $("#<%=txtDefaultValue.ClientID%>").prop("class", "date1");
            }
            else {
                $("#<%=txtDefaultValue.ClientID%>").prop("class", "");
            }
        });

what is the possible way to achieve this. 实现此目标的可能方法是什么?

If you want to remove it (keep it enable for other purpose) then you can use destroy method 如果要删除它(使其保持启用以用于其他目的),则可以使用destroy方法

$("#<%=txtDefaultValue.ClientID%>").datepicker("destroy");

else 其他

You can set option enable and disable, on change event of ddlDataType drowndown list. 您可以在ddlDataType drowndown列表的更改事件上设置启用和禁用选项。

$("#<%=txtDefaultValue.ClientID%>").datepicker('enable');

$("#<%=txtDefaultValue.ClientID%>").datepicker('disable');

alternative you can also set options to enable disable datepicker 另外,您还可以设置选项以启用禁用日期选择器

//To enable

$("#<%=txtDefaultValue.ClientID%>").datepicker( "option", "disabled", false );

//To disable

$("#<%=txtDefaultValue.ClientID%>").datepicker( "option", "disabled", true );

If you just want your datepicker to be shown or hidden, you can try this code (assuming you are using jQuery). 如果只希望显示或隐藏日期选择器,则可以尝试以下代码(假设您正在使用jQuery)。

    if ($('#<%=ddlDataType.ClientID %> option:selected').text().toLowerCase() == "date") 
    {
              $(".date1").css("display", "block");
    }
    else {
              $(".date1").css("display", "none");
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM