我有一个多步骤的表格。但是,我想单独打印并保存。问题是在html2canvas完成渲染之前,信息已经保存。因此导致图像文件为空。以下是我的代码。
html2canvas($('#content'), {
onrendered: function (canvas) {
var all = document.getElementsByClassName("tab");
html2canvas(document.getElementsByClassName("tab")[0], {
onrendered: function (canvas) {
Student.DocumentData = canvas.toDataURL().replace(/^data[:]image\/(png|jpg|jpeg)[;]base64,/i, "");
Student.DocumentName = 'Student Registration Form';
}
})
html2canvas(document.getElementsByClassName("tab")[1], {
onrendered: function (canvas) {
Student.DocumentData2 = canvas.toDataURL().replace(/^data[:]image\/(png|jpg|jpeg)[;]base64,/i, "");
Student.DocumentName2 = 'SPH Form';
}
})
html2canvas(document.getElementsByClassName("tab")[2], {
onrendered: function (canvas) {
Student.DocumentData3 = canvas.toDataURL().replace(/^data[:]image\/(png|jpg|jpeg)[;]base64,/i, "");
Student.DocumentName3 = 'Parent Consent Form';
}
})
}
var request = $.ajax({
url: "/API/Students/",
method: "POST",
cache: false,
data: Student,
dataType: "json",
error: function (jqXHR, status, error) {
alert(jqXHR.status + '. ' + jqXHR.statusText + '. ');
},
success: function (data, status, jqXHR) {
var msg = "";
for (index = 0; index < data.Message.length; ++index) {
msg += data.Message[index] + "\n";
}
alert(msg);
if (data.StudentID !== 0) {
$("input[id!='btnSubmit'],select,textarea").each(function () {
$(this).val('');
});
}
location.reload();
},
complete: function (jqXHR, status) {
$('#btnSubmit').prop('disabled', false);
}
});
}
});