我正在学习javascript。我陷入了这段代码的中间。我已经搜索了很多关于这一点,但我不明白答案。
这是我的JavaScript代码:
我正在调用downloadImages3()函数而不执行for循环,下一个函数正在调用,但我想在完成downloadImages3()之后执行downloadIamges4()。
function downloadImages3() {
var e = 0;
var length = $(".myFile").length;
alert("length=" + length);
for (e = 0; e < $(".myFile").length; e++) {
html2canvas($('myFile')[e], {
onrendered: function(canvas) {
var myImage = canvas.toDataURL("image/jpeg");
imagenameurl.push(myImage);
alert("myImage=" + myImage);
}
});
} //for loop end
downloadIamges4();
} // this is my first function and iam calling another function with "downloadIamges4()"
// this is another function
function downloadIamges4() {
var url = "/xxxxxxx/download/ConvertVideo.action?sourceUrl=" + imagenameurl;
alert("url=" + url);
$.ajax({
url: url,
success: function(response) {
alert("response=" + response);
}
});
}
答案 0 :(得分:1)
试试这个
$(".myFile").each(function() {
html2canvas($(this), {
onrendered: function(canvas) {
var myImage = canvas.toDataURL("image/jpeg");
imagenameurl.push(myImage);
if (imagenameurl.length == $(".myFile").length) downloadImages4();
}
});
});