gpt4 book ai didi

javascript - 文本框属性更改不起作用 jQuery

转载 作者:行者123 更新时间:2023-12-02 21:28:16 25 4
gpt4 key购买 nike

我有一个下拉菜单,使用此下拉菜单尝试更改属性。第一次页面加载时,它工作正常。假设我选择文本工作正常,如果我数字工作正常但是当选择“日期”,然后在“数字”之后,文本框显示日历和数字。请看图片 enter image description here

<asp:DropDownList ID="dpType" runat="server" Visible="true">
<asp:ListItem Value="0">Select Type</asp:ListItem>
<asp:ListItem Value="1">Text</asp:ListItem>
<asp:ListItem Value="2">Number</asp:ListItem>
<asp:ListItem Value="3">Date</asp:ListItem>
</asp:DropDownList>

这是我的 Jquery 代码。当我的下拉值为“3”时,我想显示如图所示的日历。

 $("#<%= dpType.ClientID %>").on('change', function () {
//alert(this.value);
var v = this.value;
console.log(v);
$("#<%= txtTypeValue.ClientID %>").prop("disabled", true);
if (v == '0' || v == 0) {
<%--$("#<%= txtTypeValue.ClientID %>").html("");--%>
$("#<%= txtTypeValue.ClientID %>").prop("disabled", true);
$('#<%= txtTypeValue.ClientID %>').val("");
}

if (v == '1' || v== "1") {
$("#<%= txtTypeValue.ClientID %>").prop("disabled", false);
$('#<%= txtTypeValue.ClientID %>').val("");
$('#<%= txtTypeValue.ClientID %>').removeClass();
$("#<%= txtTypeValue.ClientID %>").prop('type', 'text');
} else if (v == '2' || v == "2") {
$("#<%= txtTypeValue.ClientID %>").prop("disabled", false);
$('#<%= txtTypeValue.ClientID %>').val("");
$("#<%= txtTypeValue.ClientID %>").prop('type', 'number');
} else if (v == '3' || v == "3") {
$("#<%= txtTypeValue.ClientID %>").prop("disabled", false);
$('#<%= txtTypeValue.ClientID %>').val("");
//$("#<%= txtTypeValue.ClientID %>").prop('type', 'date');
$("#<%= txtTypeValue.ClientID %>").datepicker({
dateFormat: 'mm-dd-yy'
});
}
});

最佳答案

您是否询问当您将其类更改为“datepicker”时,日期输入的值未清除?如果是,则尝试触发更改事件。

像这样

$('#<%= txtTypeValue.ClientID %>').val("").trigger("change");

那么它应该可以工作。

关于javascript - 文本框属性更改不起作用 jQuery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60681525/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com