我正在使用以下脚本:

http://validity.thatscaptaintoyou.com/Demos/index.htm

这是我正在使用的示例脚本:

    <head>
        <title>Simple</title>
        <link type="text/css" rel="Stylesheet" href="jquery.validity.css" />

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" src="/js/jquery.validity.js"></script>

<script>
        $(function() {
            $("form").validity(function() {
                $("#quantity")
                    .require()
                    .match("number");
            });
        });
    </script>
</head>
<body>
    <form method="get" action="">
        <input type="text" id="quantity" />
        <br />
        <input type="submit" />
    </form>
</body>
</html>


上面的方法很好,但是现在当我想要自定义消息内容和看起来时,我陷入了困境。

jquery.validity.js是进行此更改的文件,我能够找到我可以自定义的代码段,该代码段在第91-95行可用:

// Built-in set of default error messages (for use when a message isn't
// specified):
messages:{

    require:"<div style='font-size:25px;'>#{field} is required.</div>",


现在如何在每个输入字段旁边显示此错误消息,以及如何自定义每个字段显示不同的消息?

最佳答案

答案在the very same page you linked us to上。你还看吗

// A specific error message is attached to a specific input.
$("#ssn").require("Your Social Security Number is required to proceed.");

07-25 21:56
查看更多