问题描述
我的jQuery脚本看起来像(表单正在提交要上传的文件):
My jQuery script looks something like (the form is submitting files to upload):
$("#addMore").click(function() {
$("#progForm").submit();
$("#upTar").css("display","block");
$("#title").val("");$("#obj").val("");$("#theory").val(""); $("#code").val("");$("#output").val("");$("#conc").val("");
});
我想将代码从$(#upTar")开始执行,直到表单提交完成(即文件已上传且PHP脚本已响应)为止.
I want to delay the execution of the code beginning from $("#upTar") until the form submission is completed (that is the files are uploaded and PHP script has responded).
修改
#upTar是iframe,是表单提交的目标.我希望仅在通过表单操作脚本生成其内容后才显示#upTar.
#upTar is an iframe and the target of the form submission. I want #upTar to be displayed only after its content has been generated from the form action script.
谢谢!
解决方案后的代码
$("#addMore").click(function() {
$("#progForm").submit();
$('#upTar').load(function() {
$("#upTar").css("display","block");
$("#title, #obj, #theory, #code, #output, #conc").val("");
});
});
推荐答案
无法在浏览器中使JavaScript等待"任何东西.在这种情况下,您可以做几件事:
There's no way to make JavaScript in a browser "wait" for anything. In this case, there are a couple things you could do:
-
您可以将CSS更改等放入目标
<iframe>
$('#upTar').load(function() {
$("#upTar").css("display","block");
$("#title, #obj, #theory, #code, #output, #conc").val("");
}
您可以将代码放入从<iframe>
本身执行的POST形式的响应中.
You could put code in the response to the form POST that executes from the <iframe>
itself.
$(function() {
(function($) {
$("#upTar").css("display","block");
$("#title, #obj, #theory, #code, #output, #conc").val("");
})(window.parent.$);
});
这篇关于jQuery/JavaScript-延迟到上传完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!