У меня есть следующая форма
<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 () работает, и я знаю это, потому что я поместил вызов alert () в .click () и получил окно с предупреждением.
Запустив следующее, я вижу, что .submit () для моей формы НЕ переопределяется где-либо еще:
var submitEvents = $('#myForm').data("events").submit;
jQuery.each(submitEvents, function(key, value) {
alert(value);
});
Кроме того, я не получаю ошибок Javascript.
А идеи почему нажатие Preview (видимо) ничего не дает?