我有問題來設置貨幣texboxt在下拉初始加載時,它只會在下拉更改後更改,下拉列表填充數據庫使用codebehind c#和填充下拉改變我用ajax設置TextBox基於來自DropdownList的值(由數據庫填充)在初始加載
以及這裏的代碼 下拉
<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;
}
任何人都可以提供幫助嗎?
在下拉列表中是否有默認值? –
沒有默認值的下拉菜單 – Ana
那麼你想顯示什麼樣的價值而不需要更改? –