简体   繁体   English

JavaScript等待事件完成

[英]JavaScript Wait Until Event Is Completed

How can I execute a function only after a html element gets value ? 我如何才能在html元素获取值后执行函数?

I've got an number input and a getJSON using its value as parameter, but the getJSON loads immediately with the initial value of the number, resulting in a null. 我有一个数字输入和一个使用其值作为参数的getJSON,但是getJSON立即以该数字的初始值加载,结果为null。 How can I avoid that ? 我该如何避免呢?

seems as if you are using some ajax call to get your desired number which is actually getting null. 似乎您正在使用一些Ajax调用来获取所需的数字,而该数字实际上为空。 you actually want to make it sync 您实际上想使其同步

if yes then, go ahead and check out 如果是的话,继续检查

Wait until all jQuery Ajax requests are done? 等到所有jQuery Ajax请求都完成了吗?

or else if you are using 否则,如果您正在使用

xhttp.open("GET", "ajax_info.txt", true);

use this instead
xhttp.open("GET", "ajax_info.txt", false);

Reference : http://www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp 参考: http : //www.w3schools.com/ajax/ajax_xmlhttprequest_send.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM