我已经在我的网站中实现了Jquery Validation Plugin(http://jqueryvalidation.org/documentation/),它使用javascript来滑动div。该插件工作正常,它验证了表单,但在重定向到感谢div后,它重定向回主页,我不知道为什么。您可以在此处查看网站:http://webdevkit.org/admin/SlowFire/index.php#,您可以在about部分下找到联系表格。
保存验证功能的代码如下所示,表单验证已经实现了:
function animate() {
var currentPageI = -1;
var pages = [
$('div.dhome'),
$('div.dabout'),
$('div.dcontact'),
$('div.dportraits'),
$('div.dpregnancy'),
$('div.dbabies-newborn'),
$('div.dbabies-3-6'),
$('div.dbabies-6-24'),
$('div.dkids'),
$('div.dfamily'),
$('div.dall-about-me'),
$('div.dcouples'),
$('div.dpets'),
$('div.dthe-experience'),
$('div.dfinishing-touches'),
$('div.dthank-you'),
];
var viewsWidth = 1300;
var showPage = function(index){
if(index === currentPageI){return;}
var currentPage = pages[currentPageI];
if(currentPage){
currentPage.stop().animate({left: -viewsWidth})
}
var nextPage = pages[index];
nextPage
.stop()
.css({left: viewsWidth + Math.max(0,(($(window).width() - 980)/2))})
.animate({left: Math.max(0,(($(window).width() - 980)/2))})
currentPageI = index;
};
var center = function(index){
if(index === currentPageI){return;}
var currPage = pages[currentPageI];
if(currPage){
currPage
.stop()
.css({left: viewsWidth + Math.max(0,(($(window).width() - 980)/2))})
.animate({left: Math.max(0,(($(window).width() - 980)/2))})
}
var nextPage2 = pages[index];
nextPage2
.stop()
.css({left: viewsWidth + Math.max(0,(($(window).width() - 980)/2))})
.animate({left: Math.max(0,(($(window).width() - 980)/2))})
currentPageI = index;
};
// show default page
showPage(0);
$('a.dhome').click(showPage.bind(null, 0));
$('a.dabout').click(showPage.bind(null, 1));
$('a.dcontact').click(showPage.bind(null, 2));
$('a.dportraits').click(showPage.bind(null, 3));
$('a.dpregnancy').click(showPage.bind(null, 4));
$('a.dbabies-newborn').click(showPage.bind(null, 5));
$('a.dbabies-3-6').click(showPage.bind(null, 6));
$('a.dbabies-6-24').click(showPage.bind(null, 7));
$('a.dkids').click(showPage.bind(null, 8));
$('a.dfamily').click(showPage.bind(null, 9));
$('a.dall-about-me').click(showPage.bind(null, 10));
$('a.dcouples').click(showPage.bind(null, 11));
$('a.dpets').click(showPage.bind(null, 12));
$('a.dthe-experience').click(showPage.bind(null, 13));
$('a.dfinishing-touches').click(showPage.bind(null, 14));
$("#contactform").validate({
submitHandler: function(form) {
showPage(15);
form.submit();
}
});
我不知道为什么它会在验证后重定向回到网站的根目录。
非常感谢!
答案 0 :(得分:0)
修复了event.preventDefault();
的问题$("#contactform").validate({
submitHandler: function(form) {
showPage(15);
event.preventDefault();
$form.submit();
}