我希望我的錯誤浮動在上面,左對齊,輸入字段不驗證。我怎樣才能做到這一點?jQuery驗證:如何不顯示錯誤?或者如何將錯誤顯示爲工具提示?
如果我不能,我怎樣才能關閉錯誤?我仍然希望字段驗證(並突出顯示錯誤),但不是要顯示實際的錯誤消息。我似乎無法在jQuery文檔中找到任何可讓我將它們打開/關閉的東西......?
我希望我的錯誤浮動在上面,左對齊,輸入字段不驗證。我怎樣才能做到這一點?jQuery驗證:如何不顯示錯誤?或者如何將錯誤顯示爲工具提示?
如果我不能,我怎樣才能關閉錯誤?我仍然希望字段驗證(並突出顯示錯誤),但不是要顯示實際的錯誤消息。我似乎無法在jQuery文檔中找到任何可讓我將它們打開/關閉的東西......?
您希望使用errorPlacement選項,並可能使用errorContainer和errorElement進一步自定義。
見http://docs.jquery.com/Plugins/Validation/validate#toptions
使用errorPlacement屬性的jQuery驗證電話,爲J庫珀建議:
$(...).validate({
errorPlacement: function(error, element) {
error.insertBefore(element);
}
});
和CSS樣式的錯誤(在你的樣式表,或者單個元素):
label.error {
/* Move the error above the input element. */
position: absolute;
line-height: 1.5em;
margin-top: -1.5em;
background-color: red;
color: white;
padding: 0 2px;
}
對於jQuery位:應該使用insertBefore()而不是before()。謝謝! – neezer 2009-06-19 15:43:52