Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.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
jQuery验证插件,$(“表单”)。提交不会验证表单_Jquery_Jquery Validate - Fatal编程技术网

jQuery验证插件,$(“表单”)。提交不会验证表单

jQuery验证插件,$(“表单”)。提交不会验证表单,jquery,jquery-validate,Jquery,Jquery Validate,我有一张表格: <form id="sForm"> <input type=text id="msg"> <input type="button" id="cli"> </form> 当我使用submit时 $(“#sForm”).submit() 表单上显示了错误消息,但仍提交了该消息。 当我单击用户功能时,如: $(“#cli”)。单击() 成功了! 发生了什么事?这是你的问题。您不能在验证方法中使用id。因此,将HTML更改

我有一张表格:

 <form id="sForm">
   <input type=text id="msg">
   <input type="button" id="cli">
 </form>
当我使用submit时
$(“#sForm”).submit()
表单上显示了错误消息,但仍提交了该消息。 当我单击用户功能时,如:
$(“#cli”)。单击()
成功了!
发生了什么事?

这是你的问题。您不能在验证方法中使用
id
。因此,将HTML更改为使用name属性


检查此项

这是您的问题。您不能在验证方法中使用
id
。因此,将HTML更改为使用name属性


检查此项

如果您有几个问题,其中任何一个都会破坏jQuery验证插件

1) 您需要在选项周围添加一组大括号,
{}

$("#sForm").validate({
    // your options
});
2) 您的
消息
选项拼写错误为
消息

3) 您的
消息
选项后缺少逗号

4) 您的输入元素必须包含唯一的
名称
属性:

<input type="text" name="msg" id="msg">
工作代码

$(document).ready(function () {  // <- ensure the DOM is ready

    $("#sForm").validate({  // <- the braces were missing
        rules: {
            msg: {  // <-  "msg" is supposed to be the name attribute
                required: true
            }
        },
        messages: { // <- this was misspelled as "message"
            msg: {
                required: "please input msg"
            }
        },  // <-  this comma was missing
        errorPlacement: function (error, element) {
            error.insertAfter(element);
        }
    });

});
<form id="sForm">
    <input type="text" name="msg" id="msg" />
    <input type="submit" id="cli" />
</form>

$(document).ready(function(){/您有几个问题,其中任何一个都会破坏jQuery验证插件

1) 您需要在选项周围添加一组大括号,
{}

$("#sForm").validate({
    // your options
});
2) 您的
消息
选项拼写错误为
消息

3) 您的
消息
选项后缺少逗号

4) 您的输入元素必须包含唯一的
名称
属性:

<input type="text" name="msg" id="msg">
工作代码

$(document).ready(function () {  // <- ensure the DOM is ready

    $("#sForm").validate({  // <- the braces were missing
        rules: {
            msg: {  // <-  "msg" is supposed to be the name attribute
                required: true
            }
        },
        messages: { // <- this was misspelled as "message"
            msg: {
                required: "please input msg"
            }
        },  // <-  this comma was missing
        errorPlacement: function (error, element) {
            error.insertAfter(element);
        }
    });

});
<form id="sForm">
    <input type="text" name="msg" id="msg" />
    <input type="submit" id="cli" />
</form>

$(document).ready(function(){//您编写的代码完全破坏了jQuery验证插件。请在
$(“#cli”)中显示一个JSFIDLE演示。单击()
可以成功。您编写的代码完全破坏了jQuery验证插件。请在
$(“#cli”)中显示一个JSFIDLE演示。单击()
可以成功。+1太好了。我正忙着制作小提琴。不过你的答案解释得很好。+1太好了。我正忙着制作小提琴。不过你的答案解释得很好。