我正在登录页面上,我想在输入标记
中输入错误现在我在登录面板的顶部收到错误。
这是代码。
$(document).ready(function () {
$("#form1").validate({
debug: false,
errorClass: "error error_red",
rules: {
username: {
required: true,
email: true
},
password: {
required: true,
minlength: 5
}
},
messages: {
username: "Please enter a valid email address",
password: {
required: "Please provide a password",
minlength: "Your password must be at least 5 characters long"
}
},
invalidHandler: function (form, validator) {
// This handler will show only one error at time - the first in this instance //
var errors = validator.numberOfInvalids();
//alert("error" + errors);
if (errors) {
$("#errbox").html(validator.errorList[0].message);
$("#errbox").show();
validator.errorList[0].element.focus();
} else {
$("#errbox").hide();
}
},
errorPlacement: function (error, element) {
// Override error placement to not show error messages beside elements //
},
});
});
以下是Fiddle Link
问候
马哈德
答案 0 :(得分:1)
您可以使用输入中的占位符属性来设置错误消息:
$('#myInput').attr("placeholder", "This input has an error");
这里有fiddle,表明它有效。