我有一个表单,我试图在fancybox(www.fancybox.net)内提交。如果我直接转到表格,它会提交罚款。但是,如果我在页面内部加载表单,我想从窗体调用fancybox不会提交,fancybox消失,页面刷新。我已经尝试了fancybox和facebox到同一个问题..下面是我已经在主页中的所有JQuery代码。此页面打开fancybox并在后面提交表单。该表格是为了显示一个感谢消息从窗口时,它提交刷新页面,而不是..任何帮助深表感谢:jQuery表单提交问题
的JavaScript:
$(document).ready(function() {
$("#various1").fancybox({
'opacity': true,
'overlayShow': false,
'transitionIn': 'none',
'autoscale': 'false',
'transitionOut': 'none'
});
$("submit").submit(function() {
alert('it submits');
// we want to store the values from the form input box, then send via ajax below
var name = $('#name').attr('value');
var email = $('#email').attr('value');
var password = $('#password').attr('value');
var custom1 = $('#custom1').attr('value');
var custom2 = $('#custom2').attr('value');
var custom3 = $('#custom3').attr('value');
var custom4 = $('#custom4').attr('value');
var custom5 = $('#custom5').attr('value');
var custom6 = $('#custom6').attr('value');
var custom7 = $('#custom7').attr('value');
var custom8 = $('#custom8').attr('value');
var custom9 = $('#custom9').attr('value');
var custom10 = $('#custom10').attr('value');
$.ajax({
type: "POST",
url: "test.php",
data: "name=" + name + "& email=" + email + "& password=" + password + "& custom1=" + custom1 + "& custom2=" + custom2 + "& custom3=" + custom3 + "& custom4=" + custom4 + "& custom5=" + custom5 + "& custom6=" + custom6 + "& custom7=" + custom7 + "& custom8=" + custom8 + "& custom9=" + custom9 + "& custom10=" + custom10,
success: function() {
$('submit').fadeOut(function() {
$('div.success').fadeIn();
});
}
});
return false;
})
; });
链接形式:
<a id="various1" href="register.php">
我没有看到实际的代码中的错误,其中的工作示例的链接去了哪里? – Valerij 2011-03-16 00:35:46
你不应该使用'.attr('value')' - jQuery拥有'.val()'是有原因的。另外,http://jsbeautifier.org/在发布代码之前格式化代码是一件好事。 – ThiefMaster 2011-03-16 00:38:36