[英]Pausing javascript processing?
The following code works flawlessly if I uncomment the "alert"s. 如果我取消对“警报”的注释,则以下代码可以正常工作。 This is what I've figured out for doing a set of cascading dropdowns where the user selects Country, then State, then City. 这是我在进行一系列级联下拉菜单时发现的,用户在下拉菜单中依次选择“国家/地区”,“州/州”和“城市”。
With the alerts uncommented, it's like the values haven't gotten updated yet. 在未注释警报的情况下,好像值尚未更新。 I've tried a lot of stuff, but I've had no luck. 我尝试了很多东西,但没有运气。 I'm sure I'm doing something stupid. 我确定我在做一些愚蠢的事情。 Any help is greatly appreciated. 任何帮助是极大的赞赏。
Thanks! 谢谢!
$(document).ready(function () {
$("#Country").change(function () {
$("#City").html("");
var id = $("#Country").val();
getStates(id);
// alert("CountryId = " + id);
var stateId = $("#State").val();
// alert("stateId = " + stateId);
var stateId = $("#State").val();
alert("stateId = " + stateId);
$(document).ready(function() {
getCities(stateId);
});
});
$("#State").change(function(){
var id = $("#State").val();
id = (id==null)?1:id;
getCities(id);
});
});
If function getStates is asynchronous request to the server then you have to add success callback to it. 如果getStates函数是对服务器的异步请求,则必须向其添加成功回调。 If not it is weird. 如果不是这样,那就太奇怪了。
btw. 顺便说一句 $(document).ready inside document ready doesn't make any sense. $ {document).ready内部文档就绪没有任何意义。
Your code does not make much sense 您的代码没有多大意义
Perhaps this is what you mean 也许这就是你的意思
$(document).ready(function () {
$("#Country").change(function () {
var id = $(this).val();
getStates(id);
});
$("#State").change(function () {
var id = $(this).val();
getCities(id);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.