我在初始加载时从下拉列表中设置货币文本框有问题,它只在下拉列表更改后才会改变,由数据库使用码后的c#填充的下拉列表,对于下拉更改,我使用ajax。
这是代码下拉列表
<asp:DropDownList ID="ddlPaymentCurrency" CssClass="form-control" runat="server" onblur="showCRate2()" onChange="showCRate2()" onkeyup="showCRate2()"></asp:DropDownList>和函数ddlPaymentCurrency的变化
function showCRate2(obj) {
this.curr();
var selectedCurrency = $('#<%=ddlPaymentCurrency.ClientID%>').val();
console.log(selectedCurrency);
if (selectedCurrency != null && selectedCurrency != "") {
$.ajax({
type: "POST",
url: "TopUp.aspx/getCurr",
data: '{id:"' + selectedCurrency + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
var o = response.d;
$('#<%=hfCurrencyRate.ClientID%>').val(o.RateBuy);
$('#<%=hfCR.ClientID%>').val(o.RateBuy);
},
error: function (response) {
alert('error')
}
});
}
}和webmethod
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static MukyaServiceReference.CurrRate getCurr(int id)
{
var CR = client.GetCurrRates(id);
return CR;
}有人能帮忙吗?
发布于 2015-08-16 09:38:15
这就是如何在文本框中选择下拉列表的第一项的值。使用jquery。
$(document).ready(function(){
$('#ddlPaymentCurrency').val( $('#ddlPaymentCurrency option:first-child').val() );
$('#yourTextBoxId').val($('#ddlPaymentCurrency').val());
});发布于 2015-08-15 10:05:00
您可以根据页面加载时的下拉列表值或在前面使用JQuery设置文本框的值。
https://stackoverflow.com/questions/32023438
复制相似问题