我正在尝试通过代码创建并提交表单。下面有什么问题?
$('#btnPrintInvoicePerFile').on('click', function (event) {
event.preventDefault(); //stop link default
var componentInvoiceId = EberlsComponentInvoiceForm.componentInvoice.Id;
console.log(componentInvoiceId);
$('<form>', {
"id": "getInvoiceImage",
"html": '<input type="text" id="componentInvoicId" name="componentInvoicId" value="' + componentInvoiceId + '" />',
"action": window.siteRoot + 'ComponentInvoice/GetInvoiceImage/'
}).submit();
});
答案 0 :(得分:29)
尝试首先将表单附加到body元素:
$('<form>', {
"id": "getInvoiceImage",
"html": '<input type="text" id="componentInvoicId" name="componentInvoicId" value="' + componentInvoiceId + '" />',
"action": window.siteRoot + 'ComponentInvoice/GetInvoiceImage/'
}).appendTo(document.body).submit();