在初始加载时根据下拉列表中的值设置文本框(由数据库填充)
Set TextBox Based on Value From DropdownList (populated by database) on initial Load
我在初始加载时从下拉菜单设置货币文本框有问题,它只有在下拉菜单更改后才会更改,该下拉菜单使用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());
});
您可以根据页面加载时的下拉列表值或在前端使用JQuery设置文本框的值
相关文章:
- 使用jQuery重置文本,同时存在AJAX调用
- 将指针事件限制为SVG文本填充
- 我可以重置文本输入而不清除它吗
- Ng模型在AngularJS中重置文本区域后未更新
- 用数字而不是文本填充文本框值
- 在 JavaScript 中重置文本区域高度
- 阻止按钮重置文本框值
- 如何自动用文本填充文本字段
- 阻止重置文本区域
- 单击用文本填充输入框
- 输入后重置文本区域
- Extjs组合框在存储区未加载任何结果时保持重置文本值
- 弹出窗口中的一组链接,用设置的文本填充特定命名的字段
- D3树状布局:如何用文本填充矩形,但使其大小一致
- 使用javascript重置文本框密码
- 如何隐藏质量上的下一个按钮,直到文本字段被文本填充
- Kineticjs文本填充干扰鼠标悬停事件
- Javascript(没有库)分割文本,用不同的文本填充文本框
- 单击将唯一文本填充到文本框中
- 当提交按钮时,Javascript没有重置文本框中的内容