gpt4 book ai didi

javascript - 我需要有关从 ASP 下拉列表中设置值的帮助

转载 作者:行者123 更新时间:2023-11-30 19:23:09 27 4
gpt4 key购买 nike

我有一个 asp 下拉列表。我想选择来自客户端的值(value)。我可以从客户端获取数据,但我无法通过 js 将其设置为我的 asp 下拉列表

HTML

<div class="col-md-6 form-group">
<asp:Label ID="ATRRegionCountryLabel" AssociatedControlID="ATRRegionCountryDropDownList" CssClass="col-sm-4 control-label" runat="server" Text="Country" />
<p class="col-sm-8">
<asp:DropDownList ID="ATRRegionCountryDropDownList" CssClass="form-control select" data-live-search="true" data-callback="hotels.aspx?cmd=city" data-related="select-location" runat="server" ClientIDMode="Static">
<asp:ListItem Value="0" Text="Please Select" />
</asp:DropDownList>
</p>
</div>

JS

$(document).on('click', '#btn-region-edit', function (e) {
e.preventDefault();
var $this = $(this),
id = $this.data('id'),
name = $this.data('name'),
country = $this.data('country');
$("#<%=ATRRegionCountryDropDownList.ClientID%>").val('210');
alert(country);

});

最佳答案

我按照下面的代码解决了

HTML

 <div class="col-md-6 form-group">
<asp:Label ID="ATRRegionCountryLabel"
AssociatedControlID="ATRRegionCountryDropDownList" CssClass="col-sm-4 control-label"
runat="server" Text="Country" />
<p class="col-sm-8">
<asp:DropDownList ID="ATRRegionCountryDropDownList" CssClass="form-control select"
data-live-search="true" data-callback="hotels.aspx?cmd=city" data-related="select-
location" runat="server" ClientIDMode="Static">
<asp:ListItem Value="0" Text="Please Select" />
</asp:DropDownList>
</p>
</div>

JS

 $(document).on('click', '#btn-region-edit', function (e) {
e.preventDefault();
var $this = $(this),
id = $this.data('id'),
name = $this.data('name'),
country = $this.data('country');
$('#<%=ATRRegionCountryDropDownList.ClientID %>').val(country).change();
});

关于javascript - 我需要有关从 ASP 下拉列表中设置值的帮助,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57233687/

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