我正在使用jquery驗證和jquery unobtrusive驗證插件。我試圖隱藏錯誤消息,但錯誤消息沒有隱藏。我創建了一個JS提琴:jquery驗證錯誤消息不隱藏,爲什麼
以下是我在小提琴使用的代碼:
的Html
<form id="form">
Name:
<input data-val="true" data-val-length="The field First Name must be a string with a minimum length of 3 and a maximum length of 15." data-val-length-max="15" data-val-length-min="3" name="FirstName" type="text" />
<span class="field-validation-valid help-block" data-valmsg-for="FirstName" data-valmsg-replace="true"></span>
</form>
<button id="hide">Hide</button>
隱藏
JS
$("#hide").click(function(){
$("#form").data("validator").hideErrors();
});
我在這裏失蹤以及爲什麼hideErrors()函數不工作?
編輯
我不知道爲什麼你們不守不顯眼的jQuery驗證考慮同時給予答案。幾乎所有的答案都是關注如何隱藏錯誤消息,而不用擔心現有的功能,如果我們只隱藏消息就可能會中斷。我已經提到,我想要的答案
爲什麼hideErrors()函數的jquery驗證器對象不工作?
我還創建了一個最簡單的小提琴演示我的問題,check this。
我們都明白你的問題是什麼,但jQuery的驗證並不發達隱藏在點擊消息。這非常不利於用戶,因爲你看不到你做錯了什麼,許多用戶會認爲該網站無法正常工作。這就是爲什麼。所以,我認爲,沒有真正的方法來隱藏消息(請參閱文檔,在'resetForm'中調用'hideErrors()') – GuyT