gpt4 book ai didi

javascript - 在 jQuery 中将下拉列表值设置为文本框

转载 作者:行者123 更新时间:2023-12-02 19:13:00 25 4
gpt4 key购买 nike

如果我的下拉列表选择了一个值,我想在文本框中显示所选项目的文本。如果没有,我想清空它。

<asp:DropDownList ID="ddl"  runat="server" AutoPostBack="true" onselectedindexchanged="ddlSelectedIndexChanged" Width="200px" onchange="ddlChange()">
</asp:DropDownList>
<asp:TextBox ID="hdntxtbxTaksit" runat="server" Visible="false"></asp:TextBox>

我该怎么做?

最佳答案

使用 jQuery;

$().ready(function(){           
$('#<%=ddl.ClientID %>').change(function () {
$('#<%=hdntxtbxTaksit.ClientID %>').val($(this).val() == "0" ? "" : $(this).val());
});
});

编辑:使用上述方法,您不需要调用下拉列表的onchange事件。所以你的标记可以是

<asp:DropDownList ID="ddl"  runat="server" AutoPostBack="true"
onselectedindexchanged="ddlSelectedIndexChanged" Width="200px">
</asp:DropDownList>
<asp:TextBox ID="hdntxtbxTaksit" runat="server" Visible="false"></asp:TextBox>

关于javascript - 在 jQuery 中将下拉列表值设置为文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13451545/

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