我正在使用jQuery验证器来验证用户输入。我正在尝试弄清楚何时应该清除显示在无效元素旁边的自定义错误图标。下面发布的代码一直附加着错误图标。我试图在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>发布于 2012-04-27 03:17:11
这就是添加错误消息容器的地方
errorPlacement: function(error, element) {
error.wrap("<li></li>").appendTo($("#dvErrorSummary"));
$('<div class="errorIcon"></div>').insertAfter(element);
}仅当值小于1时,才可以使用可以检查长度属性来插入errorIcon。
发布于 2013-09-25 14:11:02
为了解决这个问题,我这样做了:)
jQuery.extend(jQuery.validator.messages, {
required: '<i class = "icon-exclamation-sign"></i>'
});我试着使用上面的方法,但我做了太多的修改,所以我意识到它不可能是正确的。希望这能有所帮助:)
https://stackoverflow.com/questions/10339824
复制相似问题