jQuery动态创建和提交表单 [英] jQuery create and submit form dynamically

查看:57
本文介绍了jQuery动态创建和提交表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过代码创建和提交表单.以下是什么问题?

I'm trying to create and submit a form through code. What's wrong with the below?

$('#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();

});

推荐答案

尝试首先将表单附加到body元素:

Try to append the form to the body element first:

$('<form>', {
    "id": "getInvoiceImage",
    "html": '<input type="text" id="componentInvoicId" name="componentInvoicId" value="' + componentInvoiceId + '" />',
    "action": window.siteRoot + 'ComponentInvoice/GetInvoiceImage/'
}).appendTo(document.body).submit();

这篇关于jQuery动态创建和提交表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆