Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Jquery验证单选按钮不工作_Javascript_Jquery_Html_Validation - Fatal编程技术网

Javascript Jquery验证单选按钮不工作

Javascript Jquery验证单选按钮不工作,javascript,jquery,html,validation,Javascript,Jquery,Html,Validation,我在表单中使用jQuery验证,验证是在进入下一步时完成的,而不是在表单提交时完成的。所有其他验证工作(文本、复选框等),但收音机不工作。请在下面找到代码和html。正如您将在js代码中看到的那样,我尝试了不同的方法在required上编写相同的check命令 HTML 完整JS $(document).ready(function(){ var current = 1; widget = $(".step"); btnnext = $(".next"

我在表单中使用jQuery验证,验证是在进入下一步时完成的,而不是在表单提交时完成的。所有其他验证工作(文本、复选框等),但收音机不工作。请在下面找到代码和html。正如您将在js代码中看到的那样,我尝试了不同的方法在required上编写相同的check命令

HTML

完整JS

$(document).ready(function(){
    var current = 1;

    widget      = $(".step");
    btnnext     = $(".next");
    btnback     = $(".back"); 
    btnsubmit   = $(".submit");

    // Init buttons and UI
    widget.not(':eq(0)').hide();
    hideButtons(current);
    setProgress(current);

    // Next button click action
    btnnext.click(function(){
        if(current < widget.length){
            // Check validation
            if($(".form").valid()){
                widget.show();
                widget.not(':eq('+(current++)+')').hide();
                setProgress(current);
            }
        }
        hideButtons(current);
    })

    // Back button click action
    btnback.click(function(){
        if(current > 1){
            current = current - 2;
            if(current < widget.length){
                widget.show();
                widget.not(':eq('+(current++)+')').hide();
                setProgress(current);
            }
        }
        hideButtons(current);
    })

    $('.form').validate({ // initialize plugin
        ignore: ":not(:visible)",
        rules: {
            name     : "required",
            email    : {required : true, email:true},
            country  : "required",
            username : "required",
            password : "required",
            question1: 'required',
            question2: 'required',
            question3: "required",
            question4: {required: true},
            question5: {required: true},
            question6: {required: true}
        },
    });

});

// Change progress bar action
setProgress = function(currstep){
    var percent = parseFloat(100 / widget.length) * currstep;
    percent = percent.toFixed();
    $(".progress-bar").css("width",percent+"%").html(percent+"%");      
}

// Hide buttons according to the current step
hideButtons = function(current){
    var limit = parseInt(widget.length); 

    $(".action").hide();

    if(current < limit) btnnext.show();
    if(current > 1) btnback.show();
    if (current == limit) { 
        // Show entered values
        $(".display label:not(.control-label)").each(function(){
            console.log($(this).find("label:not(.control-label)").html($("#"+$(this).data("id")).val()));   
        });
        btnnext.hide(); 
        btnsubmit.show();
    }
}
$(文档).ready(函数(){
无功电流=1;
小部件=$(“.step”);
btnnext=$(“.next”);
btnback=$(“.back”);
btnsubmit=$(“.submit”);
//初始化按钮和用户界面
widget.not(':eq(0)').hide();
隐藏按钮(当前);
设定进度(当前);
//下一步按钮单击操作
btnnext.单击(函数(){
if(当前<小部件长度){
//检查验证
if($(“.form”).valid(){
widget.show();
widget.not(':eq('+(当前++)+')).hide();
设定进度(当前);
}
}
隐藏按钮(当前);
})
//后退按钮单击操作
btnback.click(函数(){
如果(当前>1){
电流=电流-2;
if(当前<小部件长度){
widget.show();
widget.not(':eq('+(当前++)+')).hide();
设定进度(当前);
}
}
隐藏按钮(当前);
})
$('.form').validate({//初始化插件
忽略:“:不(:可见)”,
规则:{
名称:“必需”,
电子邮件:{required:true,email:true},
国家:“必需”,
用户名:“必需”,
密码:“必需”,
问题1:“必选”,
问题2:“必选”,
问题3:“必需”,
问题4:{必需:正确},
问题5:{必需:正确},
问题6:{必需:正确}
},
});
});
//更改进度条操作
setProgress=函数(currstep){
var percent=parseFloat(100/widget.length)*currstep;
百分比=固定的百分比();
$(“.progress bar”).css(“宽度”,百分比+“%”).html(百分比+“%”);
}
//根据当前步骤隐藏按钮
hideButtons=功能(当前){
var limit=parseInt(widget.length);
$(“.action”).hide();
如果(电流<限制)btnnext.show();
如果(当前>1)btnback.show();
如果(当前==限制){
//显示输入的值
$(“.display label:not(.control label)”)。每个(函数(){
console.log($(this.find)(“label:not(.control label)”).html($(“#“+$(this.data)(“id”).val());
});
btnnext.hide();
btnsubmit.show();
}
}

我在这里检查了所有其他问题,但没有一个能解决它

你能用Id代替name吗?我试过了,但运气不好。你能用fiddle重现这个问题吗?这需要很多代码,因为这个过程是以多步骤的形式完成的。如果有帮助,我正在使用此脚本。我没有发现单选按钮的验证代码有任何问题,但请检查单选按钮是否位于
 $('.form').validate({ 
        ignore: ":not(:visible)",
        rules: {
            name     : "required",
            email    : {required : true, email:true},
            country  : "required",
            username : "required",
            password : "required",
            question1: 'required',
            question2: 'required',
            question3: "required",
            question4: {required: true},
            question5: {required: true},
            question6: {required: true}
        },
    });
$(document).ready(function(){
    var current = 1;

    widget      = $(".step");
    btnnext     = $(".next");
    btnback     = $(".back"); 
    btnsubmit   = $(".submit");

    // Init buttons and UI
    widget.not(':eq(0)').hide();
    hideButtons(current);
    setProgress(current);

    // Next button click action
    btnnext.click(function(){
        if(current < widget.length){
            // Check validation
            if($(".form").valid()){
                widget.show();
                widget.not(':eq('+(current++)+')').hide();
                setProgress(current);
            }
        }
        hideButtons(current);
    })

    // Back button click action
    btnback.click(function(){
        if(current > 1){
            current = current - 2;
            if(current < widget.length){
                widget.show();
                widget.not(':eq('+(current++)+')').hide();
                setProgress(current);
            }
        }
        hideButtons(current);
    })

    $('.form').validate({ // initialize plugin
        ignore: ":not(:visible)",
        rules: {
            name     : "required",
            email    : {required : true, email:true},
            country  : "required",
            username : "required",
            password : "required",
            question1: 'required',
            question2: 'required',
            question3: "required",
            question4: {required: true},
            question5: {required: true},
            question6: {required: true}
        },
    });

});

// Change progress bar action
setProgress = function(currstep){
    var percent = parseFloat(100 / widget.length) * currstep;
    percent = percent.toFixed();
    $(".progress-bar").css("width",percent+"%").html(percent+"%");      
}

// Hide buttons according to the current step
hideButtons = function(current){
    var limit = parseInt(widget.length); 

    $(".action").hide();

    if(current < limit) btnnext.show();
    if(current > 1) btnback.show();
    if (current == limit) { 
        // Show entered values
        $(".display label:not(.control-label)").each(function(){
            console.log($(this).find("label:not(.control-label)").html($("#"+$(this).data("id")).val()));   
        });
        btnnext.hide(); 
        btnsubmit.show();
    }
}