jquery.validate驗證隱藏的標籤

項目中常常能遇到隱藏的<input>或者其它標籤,須要驗證,可是jquery.validate不太支持隱藏的標籤元素。css

可是,能夠這樣——>java

input.validate_hidden { position:absolute; height:0; width:0; border:0; }

加一段css,而後jquery

<div class="btn-uploadfile" id="post_img_div"><span>上傳圖片</span>
    <input name="post_img_upload" ref="post_url" id="post_img_upload" type="file"/>
    <input name="post_path" id="post_path" class="validate_hidden">
</div>

 而後,在須要被驗證的標籤中加入此style就好了。post


另外,不值得一提的是網上不少人是修改jquery.validate.min.jsurl

把js的 ignore:"hidden"spa

改爲  ignore:""code

可是此方法不提倡,畢竟作項目會是一個團隊,甚至不少團隊。這種js是不少人公用的,修改的話會產生不少未知的影響,因此很是不提倡,與其修改js源碼,還不如不用jquery.validate。圖片

相關文章
相關標籤/搜索