Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何定制JS脚本?_Javascript_Jquery_Forms_Validation - Fatal编程技术网

Javascript 如何定制JS脚本?

Javascript 如何定制JS脚本?,javascript,jquery,forms,validation,Javascript,Jquery,Forms,Validation,我正在使用以下脚本: 这是我正在使用的示例脚本: <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> &

我正在使用以下脚本:

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

    <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>

简单的
$(函数(){
$(“形式”).有效性(函数(){
$(“数量”)
.require()
.匹配(“编号”);
});    
});    

上面的内容很好,但是现在当我想要自定义消息的内容和外观时,我被卡住了

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>",
//内置的一组默认错误消息(在消息不存在时使用)
//(具体说明):
信息:{
require:“#{field}是必需的。”,
现在,我如何在每个输入字段旁边显示此错误消息,以及如何自定义每个字段显示的不同消息?

答案是打开的。您看了吗

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

谢谢。我确实查看了,但没有意识到我丢失了一个文件。如何显示选择菜单的错误?我查看了指南,发现:$(function(){$(“form”)。validity(“input:text,select”);});但不知道如何使用我的select id自定义它……有什么帮助吗?谢谢!我从未使用过此功能,但我怀疑您只是给了selectbox一个id或类,以便可以将其作为目标:
$(.mySelect”).require(“您必须提供一个选择”);