form.submit()到一个特定的DIV

form.submit() to a specific DIV

本文关键字:一个 DIV submit form      更新时间:2023-09-26

我想使用Javascript和jQuery提交一个表单到特定的div,但我不知道如何做到这一点。

下面的代码可以工作,将表单提交到当前页面的标题。

    var form,
        chart = this,
        svg = chart.getSVG(chartOptions);
    // merge the options
    options = merge(chart.options.exporting, options);
    // create the form
    form = createElement('form', {
        method: 'post',
        action: options.url
    }, {
        display: NONE
    }, doc.body);
    // add the values
    each(['filename', 'type', 'width', 'svg'], function(name) {
        createElement('input', {
            type: HIDDEN,
            name: name,
            value: {
                filename: options.filename || 'chart',
                type: options.type,
                width: options.width,
                svg: svg
            }[name]
        }, null, form);
    });
    // submit
    form.submit();
    // clean up
    discardElement(form);

我已经尝试了各种选择,但没有工作。简单来说,我想这样做:

$('#myDiv').form.submit();

或者换句话说,将提交命令发送到名为myDiv的div。

有谁知道我会怎么做吗?谢谢。

您应该能够使用这里给出的代码:

在JQuery中发布表单并在IE中填充DIV - broken

$.ajax({
  url: options.url,
  type: 'POST',
  cache: false,
  data: {
            filename: options.filename || 'chart',
            type: options.type,
            width: options.width,
            svg: svg
        },
  dataType: 'text',
  complete: function(xhr, textStatus) {
    alert('completed');
  },
  success: function(data) {
    $("#myDiv").html(data);
  },
  error: function(xhr, textStatus, errorThrown) {
    alert('woops');
  }
});
$('#myDiv').click (function () {
$("form").submit();
});