jquery validate select验证问题

验证是通过name进行 锁定的、

<select id="project_level" name="project_level" class="chosen-select" required>
                                        <option value="">请选择</option>
                                        <option value="普通">普通</option>
                                        <option value="紧急">紧急</option>
                                        <option value="非常紧急">非常紧急</option>
                                    </select>

  

 

    $("#form1").validate({
                    errorPlacement: function (error, element) {
                      if (element.parent().hasClass("input-group")) {
                         element.parent().after(error);
                      }
                      else{
                        element.after(error)
                      }  
                  },
                  errorPlacement: function (error, element) {
                     error.appendTo(element.parent()); //直接把错误信息加在验证元素后··
                 },
                    rules: {
                        project_name: { required: true},
                        project_level: {required: true},
                        project_worker: {required: true},
                        project_member: {required: true},
                    },
                    messages: {
                        project_name: {required: "请输入"},
                        project_level: {required: "请选择"},
                        project_worker: {required: "请选择"},
                        project_member: {required: "请选择"},
                    },
                    ignore:":hidden:not(select)",    //解决select被忽略验证
                });
                //当选择改变时,再校验一次
                $(".chosen-select").change(function(){  
                    $(this).valid();  
                });

  

  

posted @ 2022-01-02 22:30  柠檬青味  阅读(390)  评论(0编辑  收藏  举报