我有以下表格
<form name="myForm" id="myForm" method="post" enctype="multipart/form-data" action="script.php">
和这个 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;
});
});
我在两个不同的页面上有完全相同的两个代码。一方面,当我单击我的预览链接时,表单会提交到一个新的空白窗口。在另一页上,表单没有提交,当我单击预览时没有打开任何窗口。
.click() 正在运行,我知道这一点是因为我在 .click() 中调用了 alert() 并出现了一个警告框。
通过运行以下命令,我可以看到我的表单的 .submit() 在其他任何地方都没有被覆盖:
var submitEvents = $('#myForm').data("events").submit;
jQuery.each(submitEvents, function(key, value) {
alert(value);
});
此外,我没有收到 Javascript 错误。
以及为什么单击预览(显然)什么都不做的想法?