validate对jquery chosen-select无法验证,需要在validate加入
ignore: ":hidden:not(select)"
加入后可以成功校验,但是错误信息显示在select框上面
解决此问题是加入
errorPlacement
$("#form-add").validate({ ???ignore: ":hidden:not(select)", ???rules: { ???????id: { ???????????required: true ???????} ???}, ???messages: { ???????id: { ???????????required: "请选择关联的数据字典" ???????} ???}, ???errorPlacement:function (error, element) { ???????error.appendTo(element.parent()); ???}});
加上之后,错误信息显示在下面
想选择成功后 立刻清除错误信息,可以加入change事件
$(function() { ???$(".chosen-select").chosen({width: ‘95%‘,search_contains: true,no_results_text: "无对应数据..."}); ???$(".chosen-select").change(function () { ???????$(this).valid(); ???})});
validate验证jquery chosen相关问题
原文地址:https://www.cnblogs.com/qinyuekong/p/10250474.html