Prevent jquery-validate from using the title attribute as an error message?

大城市里の小女人 提交于 2019-12-22 06:36:24

问题


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.

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>

Is there a way to prevent jquery-validate from using the title attribute as an error message?


回答1:


Try this:

Working demo http://jsfiddle.net/e6ndm/

Doc: http://jqueryvalidation.org/validate#toptions

Rest should fit your need :)

$("#mainform").validate({
    ignoreTitle: true
});


来源:https://stackoverflow.com/questions/19503864/prevent-jquery-validate-from-using-the-title-attribute-as-an-error-message

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!