초기로드시 드롭 다운에서 통화 texboxt를 설정하는 데 문제가 있습니다. 드롭 다운 변경 후에 만 변경됩니다. 해당 드롭 다운은 코드 숨김 C #을 사용하여 데이터베이스로 채워지고 드롭 다운 변경에는 ajax를 사용합니다.
여기에 코드 드롭 다운이 있습니다.
<asp:DropDownList ID="ddlPaymentCurrency" CssClass="form-control" runat="server" onblur="showCRate2()" onChange="showCRate2()" onkeyup="showCRate2()"></asp:DropDownList>
및 함수 ddlPaymentCurrency onchange
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;
}
아무도 도울 수 있습니까?
이렇게하면 드롭 다운의 첫 번째 항목 값이 텍스트 상자에 표시됩니다. jquery 사용.
$(document).ready(function(){
$('#ddlPaymentCurrency').val( $('#ddlPaymentCurrency option:first-child').val() );
$('#yourTextBoxId').val($('#ddlPaymentCurrency').val());
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다