1. 程式人生 > >解決jQuery Validate外掛無法校驗select元件

解決jQuery Validate外掛無法校驗select元件

$.validator.setDefaults({highlight:function(e){$(e).closest(".form-group").removeClass("has-success").addClass("has-error")},
    success:function(e){e.closest(".form-group").removeClass("has-error").addClass("has-success")},
    errorElement:"span",errorPlacement:function(e,r){e.appendTo(r.is(":radio"
)||r.is(":checkbox")?r.parent().parent().parent():r.parent())},errorClass:"help-block m-b-none",validClass:"help-block m-b-none" }); $().ready(function(){ var validator = $("#from").validate({ ignore: ":hidden:not(select)",//解決無法校驗select submitHandler: function()
{
submitForm(); } }); });