阻止jquery-validate使用title属性作为错误消息? [英] Prevent jquery-validate from using the title attribute as an error message?
问题描述
Jquery validate使用 title
属性作为错误消息。我使用 title
属性来提供用户工具提示,但我不希望它替换验证错误消息。
Jquery validate uses the title
attribute as the error message. I use the title
attribute to provide user tooltips, but I don't want it to replace validation error messages.
在这个完整的示例中,我将姓氏字段设置为具有标题
属性,同时保留名字没有标题
属性的字段。表单提交后,名字字段会正确显示错误消息 - 此字段是必需的。,同时显示姓氏字段 title
属性的内容。
In this complete example, I've set the Last Name field to have a title
attribute while leaving the First Name field without a title
attribute. When the form submits, the First Name field properly displays the error message - "This field is required.", while the Last Name field displays the contents of the title
attribute.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js"></script>
</head>
<body>
<form method="post" id="mainform">
Last Name
<input name="LastName" type="text" required="required" title="I don't want this to appear on my form" />
<br />
First Name
<input name="FirstName" type="text" required="required" />
<br />
<input type="submit" value="Submit" />
</form>
<script>
$("#mainform").validate();
</script>
</body>
</html>
有没有办法阻止jquery-validate使用标题
属性作为错误消息?
Is there a way to prevent jquery-validate from using the title
attribute as an error message?
推荐答案
试试这个:
工作演示 http://jsfiddle.net/e6ndm/
Doc: http://jqueryvalidation.org/validate#toptions
休息应符合您的需要:)
$("#mainform").validate({
ignoreTitle: true
});
这篇关于阻止jquery-validate使用title属性作为错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!