我的頁面上有jQuery驗證(使用twitter引導),我使用以下ASP.NET MVC註釋。從Jquery中的元素中移除驗證
[DisplayName("Text)"),Range(100,35000)]
public decimal Field { get; set; }
元素與補充說:
@Bootstrap.TextBoxFor(x => x.Field, htmlAttributes: new {@class="ignore",id="field" })
的問題是,我想允許在該領域的空白值,但保留範圍驗證的情況下,一個非空的值寫入。
這是我的javascript代碼:
$("#Field").on("keyup", function (e) {
e.preventDefault();
if ($(this).val() == "") {
$(this).removeClass("input-validation-error");
$(this).addClass("valid");
$(this).next().html("");
$(this).parent().parent().removeClass("error");
}
})
$.validator.setDefaults({ ignore: ".ignore" });
** **報價:_「我希望允許在該領域的空白值,但保留範圍驗證在一個非空值被寫入案」 _〜驗證input元素,但不能使它'required'簡單意味着在保持'range'規則的同時去除'required'規則。 – Sparky 2013-02-12 17:10:38
另外,你爲什麼要創建一個'keyup'函數來完成插件已經做的或者能夠做的一大堆事情呢? – Sparky 2013-02-12 17:13:27