gpt4 book ai didi

jquery - onchange 下拉列表

转载 作者:行者123 更新时间:2023-12-03 21:46:04 26 4
gpt4 key购买 nike

我的问题是我所问问题的延续,请参阅链接。 Load Country/State/City

我已经展开以从数据库加载我的下拉列表,我只需要一种方法在我的第一个下拉列表和第二个下拉列表中连接 onchange 方法,请查看代码。感谢任何帮助。

附加最新代码:

<select id="country"  onchange="getStateByCountryId()"></select> <br />
<select id="state"></select> <br />


$(document).ready(function() {
var options = {
type: "POST",
url: "SearchPage.aspx/LoadCountry",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",

success: function(msg) {

var returnedArray = msg.d;
country = $("#country");
country.append('<option>Select a Country</option>');

for (i = 0; i < returnedArray.length; i++) {
country.append("<option value='" + returnedArray[i].Id + "'>" + returnedArray[i].Name + "</option>");
}


}
};
$.ajax(options);
});


function getStateByCountryId() {

$("#country").change(function()
{
var _selected = $("#country").val();
var options =
{
type: "POST",
url: "SearchPage.aspx/StateBy",
data: "{'countryId':'" + _selected + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",

success: function(msg) {
$('#state').empty();
var returnedArray = msg.d;


state = $("#state");
for (var i = 0; i < returnedArray.length; ++i) {
state.append("<option value='" + returnedArray[i].Id + "'>" + returnedArray[i].Name + "</option>");
}
}
};
$.ajax(options);
});
}

但不填充?我正在做的事情就是你想要做的事情吗?

谢谢。

最佳答案

$("#state").change(function(){
//on-change code goes in here.
//variable "this" references the state dropdown element
});

关于jquery - onchange 下拉列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2668574/

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