我正在使用 jQuery Validator 来验证用户输入。我试图弄清楚何时应该清除无效元素旁边显示的自定义错误图标。下面发布的代码不断附加错误图标。我试图在showErrors
事件中清除它,但没有运气。
$("#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>