Jquery 验证不需要';不要检查规则
我使用jQuery验证插件检查网站上的表单。这是我的HTML表单的一部分,用于检查Jquery 验证不需要';不要检查规则,jquery,jquery-validate,Jquery,Jquery Validate,我使用jQuery验证插件检查网站上的表单。这是我的HTML表单的一部分,用于检查 <form id ="formCharacteristics" align="center"> <dl> <dt style="text-align:left; margin-left:120px;"><label for="cpuname">CPU name</label></dt> <dd&g
<form id ="formCharacteristics" align="center">
<dl>
<dt style="text-align:left; margin-left:120px;"><label for="cpuname">CPU name</label></dt>
<dd><input type="text" id="cpuname" placeholder="Intel 8086"></dd>
<div align="right" style="margin-right:30px">
<button id="buttonSubmitCharacteristics" type="button" onclick = "AddCPU()" >Done</button>
<button type="button" onclick="HideMessage()">Back</button>
</div>
</form>
验证在其他表单上正常工作,但在此表单上它不检查任何规则。我不使用相同的表单ID和输入ID。下面是用于指定规则的代码
$(document).ready(function() {
$('#formCharacteristics').validate({
rules:{
cpuname: {
required: true,
maxlength: 30,
minlength: 4
}
}
});
......
)};
您的代码:
$('#formCharacteristics').validate({
rules: {
cpuname: { // <- this is the NAME attribute
required: true,
maxlength: 30,
....
您的代码:
$('#formCharacteristics').validate({
rules: {
cpuname: { // <- this is the NAME attribute
required: true,
maxlength: 30,
....
其中是为
cpuname
指定预期验证的代码?就我所见,表单是有效的,因为没有应用于cpuname
的规则。除非您以前调用了form.valid()
,以指定规则和其他验证选项,否则无法调用form.validate()
。验证插件要求元素有名称,而不仅仅是ID。@Barmar,“我使用一个验证插件”-基于代码,甚至不清楚他说的是哪个插件,所以我不确定为什么要用它来标记。@Sparkyform.valid()
是该插件的一部分,尽管我认为其他插件也可能有类似的方法。下面是用于指定规则的代码$(document).ready(function(){$('#formCharacteristics')。validate({rules:{cpuname:{required:true,maxlength:30,minlength:4}});});代码>其中是为cpuname
指定预期验证的代码?就我所见,表单是有效的,因为没有应用于cpuname
的规则。除非您以前调用了form.valid()
,以指定规则和其他验证选项,否则无法调用form.validate()
。验证插件要求元素有名称,而不仅仅是ID。@Barmar,“我使用一个验证插件”-基于代码,甚至不清楚他说的是哪个插件,所以我不确定为什么要用它来标记。@Sparkyform.valid()
是该插件的一部分,尽管我认为其他插件也可能有类似的方法。下面是用于指定规则的代码$(document).ready(function(){$('#formCharacteristics')。validate({rules:{cpuname:{required:true,maxlength:30,minlength:4}});});谢谢,你救了我一天。谢谢,你救了我一天。
<input type="text" name="cpuname" id="cpuname" ....