表单拒绝通过jQuery提交

Cha*_*son 2 forms jquery form-submit

我有以下表格

<form name="myForm" id="myForm" method="post" enctype="multipart/form-data" action="script.php">
Run Code Online (Sandbox Code Playgroud)

和这个jQuery

$(document).ready(function() {

  $('#previewButton').click(function() {
    // Change form's target to be in a new window.
    $('#myForm').attr('target', '_blank');

    /*
     * Create a hidden input field and add it to the form to designate that the
     * action the form is performing is a preview action.
     */
    $('#myForm').append($('<input id=\"previewAction\" name="previewAction" type=\"hidden\" />'));

    // Submit the form.
    $('#myForm').submit();

    // Change the form's target to be the current page again.
    $('#myForm').attr('target', '');

    /*
     * Remove the hidden input field we just added so that the form can submit
     * normally.
     */
    $('#previewAction').remove();

    return false;
  });

});
Run Code Online (Sandbox Code Playgroud)

我在两个不同的页面上有完全相同的两个代码.在其中一个,当我单击我的预览链接时,表单提交到一个新的空白窗口.在另一页上,表单未提交,单击"预览"时不会打开任何窗口.

.click()IS正在运行,我知道这是因为我在.click()中调用了alert()并且出现了一个警告框.

从运行以下内容,我可以看到我的表单的.submit()在其他任何地方都没有被覆盖:

var submitEvents = $('#myForm').data("events").submit;
jQuery.each(submitEvents, function(key, value) {
  alert(value);
});
Run Code Online (Sandbox Code Playgroud)

此外,我没有Javascript错误.

为什么单击预览(显然)什么都没做的想法?

Cha*_*son 6

原来有一个<input>id ='submit' 的按钮.jQuery不喜欢这个.