Javascript JQuery验证插件:无法验证引导向导的第二个setp

Javascript JQuery验证插件:无法验证引导向导的第二个setp,javascript,jquery,validation,wizard,Javascript,Jquery,Validation,Wizard,我有一个jquery步骤向导(3个步骤),其中有一个表单。当传递到下一步时,我尝试使用valid()方法验证第一步表单字段(没问题),但当我尝试验证第二步时,jquery validate始终返回true。因此,它将传递到第三步和结束步骤,而不验证第二步。请问怎么做 我有一个用于验证每个向导步骤的函数 $(文档).ready(函数(){ /*激活工具提示*/ $('[rel=“tooltip”]')。tooltip(); $('.wizard卡').bootstrapWizard({ “tab

我有一个jquery步骤向导(3个步骤),其中有一个表单。当传递到下一步时,我尝试使用valid()方法验证第一步表单字段(没问题),但当我尝试验证第二步时,jquery validate始终返回true。因此,它将传递到第三步和结束步骤,而不验证第二步。请问怎么做

我有一个用于验证每个向导步骤的函数

$(文档).ready(函数(){
/*激活工具提示*/
$('[rel=“tooltip”]')。tooltip();
$('.wizard卡').bootstrapWizard({
“tabClass”:“导航丸”,
“下一个选择器”:“.btn下一个”,
“previousSelector”:“.btn previous”,
onInit:功能(选项卡、导航、索引){
//检查选项卡的数量并填充整行
var$total=navigation.find('li').length;
$width=100/$total;
$display_width=$(document).width();
如果($display_width<600&$total>3){
$width=50;
}
navigation.find('li').css('width',$width+'%');
},
onNext:函数(选项卡、导航、索引){
如果(索引==1){
返回validateFirstStep();
}else if(索引==2){
返回validateSecondStep();
}否则如果(索引==3){
返回validateThirdStep();
}//等等。
},
onTabClick:功能(选项卡、导航、索引){
//禁用单击选项卡的可能性
返回false;
}, 
onTabShow:功能(选项卡、导航、索引){
var$total=navigation.find('li').length;
var$当前=指数+1;
var-wizard=navigation.closest('.wizard-card');
//如果是最后一个选项卡,则隐藏最后一个按钮并显示finish
如果($current>=$total){
$(向导).find('.btn next').hide();
$(向导).find('.btn finish').show();
}否则{
$(向导).find('.btn next').show();
$(向导).find('.btn finish').hide();
}
}
});
//为配置文件图片准备预览
$(“#向导图片”).change(函数(){
readURL(this);
});
$('[data toggle=“wizard radio”]')。单击(函数(){
wizard=$(this).closest('.wizard-card');
wizard.find('[data toggle=“wizard radio”]')。removeClass('active');
$(this.addClass('active');
$(向导).find('[type=“radio”]')。removeAttr('checked');
$(this.find('[type=“radio”]').attr('checked','true');
});
$('[data toggle=“wizard checkbox”]')。单击(函数(){
if($(this).hasClass('active')){
$(this.removeClass('active');
$(this).find('[type=“checkbox”]')。removeAttr('checked');
}否则{
$(this.addClass('active');
$(this.find('[type=“checkbox”]').attr('checked','true');
}
});
$height=$(document.height();
$('.set full height').css('height',$height);
});
函数validateFirstStep(){
$(“.wizard卡表单”).validate({
规则:{
名字:“必选”,
姓氏:“必需”,
电邮:{
要求:正确,
电子邮件:真的
}
},
信息:{
名字:“请输入您的名字”,
姓氏:“请输入您的姓氏”,
电子邮件:“请输入有效的电子邮件地址”,
}
}); 
如果(!$(“.wizard card form”).valid()){
//表格无效
返回false;
}
返回true;
}
函数validateSecondStep(){
//这里是第二步的代码
$(“.wizard卡表单”).validate({
规则:{
matri:“必选”
},
信息:{
矩阵:“需要矩阵”
}
}); 
如果(!$(“.wizard card form”).valid()){
console.log('invalid');
返回false;
}
返回true;

}
只需更换动画功能即可

发件人:

function refreshAnimation($wizard, index){
    total_steps = $wizard.find('li').length;
    move_distance = $wizard.width() / total_steps;
    step_width = move_distance;
    move_distance *= index;

    $wizard.find('.moving-tab').css('width', step_width);
    $('.moving-tab').css({
        'transform':'translate3d(' + move_distance + 'px, 0, 0)',
        'transition': 'all 0.3s ease-out'

    });
}

function refreshAnimation($wizard, index){
    total_steps = $wizard.find('.nav li').length;
    move_distance = $wizard.width() / total_steps;
    step_width = move_distance;
    move_distance *= index;

$wizard.find('.moving-tab').css('width', step_width);
$('.moving-tab').css({
    'transform':'translate3d(' + move_distance + 'px, 0, 0)',
    'transition': 'all 0.3s ease-out'

});
}

在第一步中添加所有验证规则

$(".wizard-card form").validate({
    rules: {
        firstname: "required",
        lastname: "required",
        email: {
            required: true,
            email: true
        },
        matri: "required"
    },
    messages: {
        firstname: "Please enter your First Name",
        lastname: "Please enter your Last Name",
        email: "Please enter a valid email address",
        matri: "Matricule required"
    }
}); 
并在第二步中检查验证

function validateSecondStep(){

//code here for second step

if(!$(".wizard-card form").valid()){
    console.log('invalid');
    return false;
}
return true;
}