Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.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
jQuery验证程序:类型上的自定义消息_Jquery - Fatal编程技术网

jQuery验证程序:类型上的自定义消息

jQuery验证程序:类型上的自定义消息,jquery,Jquery,我基本上有一个for循环,它在一堆类中循环,一个用于复选框,一个用于广播框。选择时需要将字段标记为必需,或者选中该选项,这样可以很好地工作。我只需要为每种类型显示一条自定义错误消息:复选框和单选框 我已经尝试在循环/方法中执行。validaterules{required:'请选择一个选项'}没有运气。我怎样才能做到这一点 代码: // When the DOM is ready $(document).ready(function() { /* To add more

我基本上有一个for循环,它在一堆类中循环,一个用于复选框,一个用于广播框。选择时需要将字段标记为必需,或者选中该选项,这样可以很好地工作。我只需要为每种类型显示一条自定义错误消息:复选框和单选框

我已经尝试在循环/方法中执行。validaterules{required:'请选择一个选项'}没有运气。我怎样才能做到这一点

代码:

// When the DOM is ready
$(document).ready(function() {
            /* To add more boxes to hide/show, add the name of the field to the array, 
                set the box class to that name + Hide, set the class of the field to that name
                then if radio box set value="Yes" Yes must have first letter capitlized */ 
            // storing the class names of the HTML elements we want to mess with
            var hiddenClassArray = [
                        "appliedWorkedYes",
                        "workStudyYes",
                        "workHistoryYes",
                        "workWeekEndsYes",
                        "cprYes",
                        "aedYes",
                        "aidYes",
                        "lifegaurd",
                        "wsiYes",
                        "gaurdYes",
                        "lifegaurdChk",
                        "fitnessChk",
                        "fitPTCYes",
                        "fitGrpYes",
                        "outdoorAdvChk",
                        "challengeChk",
                        "injuryCareChk",
                        "athTrainYes",
                        "serviceCenter",
                        "itDepartmentChk",
                        "marketingChk"
                        ];  

            // looping over each array element, hiding them using jQuery
            for(var i = 0; i < hiddenClassArray.length; i++){
                // jQuery to append a display none. 
                $("."+hiddenClassArray[i]+"Hide").css("display","none");    
            }

            // ************ RADIO & CHECK BOXES ************

        // jQuery's Equlivant of a for each loop, a little fancier then that 
        $.each(hiddenClassArray, function(index, radio) {

            // first is it a Check box? 
            if($("."+radio).is(':checkbox')) {
                // when we click
                $("." + radio).click(function() {
                    // if it's checked show
                    if($("."+ radio).attr('checked')){
                        // show
                        $("." + radio + "Hide").show('fast'); 
                        // make one of the group required
                        $("."+radio + "requried").addClass("required");
                    }
                    // default hide
                    else{ 
                        // hide 
                        $("."+radio + "Hide").hide("fast");
                        // remove the required class attribute
                        $("."+radio + "requried").removeClass("required");
                    }
                }); // ends .click
            } // ends if
            // if it's a radio box
            else if ($("."+radio).is(':radio')) {
                // On click
                $("."+radio).click(function(){
                    // show
                    if($(this).val()==="Yes"){
                        // show
                        $("."+radio + "Hide").show("fast");
                        // make one of the group required
                        $("."+radio + "requried").addClass("required");
                    }
                    // default, hide
                    else{ 
                        // hide
                        $("."+radio + "Hide").hide("fast");
                        // remove the required class attribute
                        $("."+radio + "requried").removeClass("required");
                    }
                }); // emds .click

            }// ends else
        }); // end .each

    // Validating data 
    $(".empForm").validate();



}); // Ending the $(Doc) Ready  
你能吐一口吗?我想如果我有地方玩的话,我可以做很多优化。我自己会做的,但真实数据是最好的,我没有这些数据。