我正在使用jQuery驗證器來驗證用戶輸入。我想弄清楚什麼時候應該清除顯示在無效元素旁邊的自定義錯誤圖標。下面發佈的代碼會附加錯誤圖標。我試圖在showErrors
事件中清除它,但沒有運氣。jquery驗證器:何時清除自定義錯誤圖標
$("#form1").validate({
onfocusout: false,
onKeyUp: false,
rules: {
txtDate:{
required: true
},
txtType:{
required: true
},
ddlTime:{
required: true
}
},
messages: {
ddlTime: {
required: "Please select an option for Time"
},
txtDate:{
required: "<br>Please enter valid date"
},
txtType: {
required: "<br>Please Enter valid type"
}
},
errorPlacement: function(error, element) {
error.wrap("<li></li>").appendTo($("#dvErrorSummary"));
$('<div class="errorIcon"></div>').insertAfter(element);
}
});
這是我的CSS看起來像:
label.error {
color: red;
font-style: italic
}
.errors { color: red; }
.errorIcon
{
background: url(../errorIcon.png);
width: 16px;
height: 16px;
display:inline;
}
這是我的HTML看起來像:
<body>
<html>
<head runat="server"></head>
<form id="form1" runat="server">
<ul id="dvErrorSummary" name="dvErrorSummary" class="errors"></ul>
<select id="ddlTime" name="ddlTime" </select>
<input id="txtDate" name="txtDate" />
<input id="txtType" name="txtType" />
</form>
</body>
</html>
長度是什麼? – Asdfg 2012-04-26 19:19:16
div class =「errorIcon」 – defau1t 2012-04-26 19:20:35
如果有多個錯誤,長度將大於1. – Asdfg 2012-04-26 19:21:47