我使用jQuery Validate,当我提交表单时,它仅显示一个必填字段,并且仅当我单击它们时才显示其他字段。
这是脚本和正文:
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>
为什么会这样?它可以工作,但是不能正常工作。我找不到解决方案。
编辑:
有时候是这样的:
最佳答案
为什么会这样?它可以工作,但是不能正常工作...
您必须在考虑进行验证的每个输入上都具有一个name
属性,并且name
是唯一可以从rules
对象的.validate()
对象引用的内容。
$("#form1").validate({
rules: {
Yritys: { // <- this must be the NAME
required: true,
minlength: 3
},
Henkilönimi: { // <- this must be the NAME
....
...我找不到解决方案
Official Documentation: Markup recommendations -
强制:所有需要验证的输入元素都必须具有“名称”属性,如果没有此属性,插件将无法工作。
您还意外地将
messages
对象放在了应该是同级的rules
内。$("#form1").validate({
rules: {
....
},
messages: {
....
}
});
演示:jsfiddle.net/2o9Lxkej