jQuery验证的奇怪行为 [英] Strange Behavior of jQuery Validate
问题描述
我使用jQuery Validate,当我提交表单时,它仅显示一个必填字段,并且仅当我单击它们时才显示其他字段.
I use jQuery Validate and when I submit the form it shows just one required field and it shows others only when I click on them, and on the next one.
这是脚本和正文:
jQuery(function () {
$("#form1").validate({
rules: {
Yritys: {
required: true,
minlength: 3
},
Henkilönimi: {
required: true,
minlength: 3
},
Asema_yrityksessa: {
required: true,
minlength: 3
},
Puhelin_Nr: {
required: true,
minlength: 3
},
e_Mail: {
required: true,
minlength: 3
},
Keskustelun_aihe: {
required: true,
minlength: 10
},
messages: {
Yritys: {
required: "You must enter something",
minlength: "You must enter more than 3 characters"
},
Henkilönimi: {
required: "You must enter something",
minlength: "You must enter more than 3 characters"
},
Asema_yrityksessa: {
required: "You must enter something",
minlength: "You must enter more than 3 characters"
},
Puhelin_Nr: {
required: "You must enter something",
minlength: "You must enter more than 3 characters"
},
e_Mail: {
required: "You must enter something",
minlength: "You must enter more than 3 characters"
},
Keskustelun_aihe: {
required: "You must enter something",
minlength: "You must enter more than 10 characters"
}
}
},
});
});
<div class="divInfo">
<form id="form1">
<span>Yritys:</span><br />
<input id="Yritys" type="text" required /><br />
<span>Henkilönimi:</span><br />
<input id="Henkilönimi" type="text" required /><br />
<span>Asema yrityksessa:</span><br />
<input id="Asema_yrityksessa" type="text" required /><br />
<span>Puhelin Nr:</span><br />
<input id="Puhelin_Nr" type="text" required /><br />
<span>e-Mail:</span><br />
<input id="e_Mail" type="text" required /><br />
<span>Keskustelun aihe:</span><br />
<textarea id="Keskustelun_aihe" maxlength="140" style="width:300px;height:150px;" required>Enter Text Here...</textarea><br />
<span style="color:red; margin-left:0;">Keskustelun aihe max 140 merkkia</span>
<div id="textarea_feedback" style="opacity:0.5"></div>
<div class="butt"><pre style="font-size:x-large">Vahvista varaus klikkamalla tässä>>>>>>>>>>>>><button id="submit" type="submit" name="appointment" value="" class="btn-warning" /></pre></div>
</form>
</div>
为什么会这样?它可以工作,但是不能正常工作.我找不到解决方法.
Why does this happen? It works, but it's not working properly. I can't find the solution.
发生这种情况:
推荐答案
为什么会这样?它可以工作,但是不能正常工作...
Why does this happen? It works, but it's not working properly ...
您必须在要进行验证的每个输入上都有一个name
属性,并且name
是唯一可以从.validate()
的rules
对象引用的东西. /p>
You MUST have a name
attribute on every input considered for validation, and the name
is the only thing that can be referenced from the rules
object of .validate()
.
$("#form1").validate({
rules: {
Yritys: { // <- this must be the NAME
required: true,
minlength: 3
},
Henkilönimi: { // <- this must be the NAME
....
...我找不到解决方法
... I can't find the solution
必填:所有需要验证的输入元素都必须具有名称"属性,如果没有该插件,插件将无法工作.
Mandated: A 'name' attribute is required for all input elements needing validation, and the plugin will not work without this.
您还不小心将messages
对象放在了应该是同级的rules
内.
You also accidentally put the messages
object inside of rules
, which are supposed to be siblings.
$("#form1").validate({
rules: {
....
},
messages: {
....
}
});
这篇关于jQuery验证的奇怪行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!