【发布时间】:2015-08-09 10:59:34
【问题描述】:
我正在开发 jQuery 验证插件。单击提交时,它首先验证并显示第一个表单并显示自定义错误消息,一旦输入了值,然后如果我单击提交,它就会隐藏第一个表单并显示第二个表单。
这是我的 HTML 代码
<form id="form1" method="post">
<div id="div_form1">
<input type = "text" id="txt_fname" name="txt_fname"/>
<select id="opt_sel" name="kindly select the value">
<option>
Select
</option>
<option>
Bananana
</option>
</select>
<button id="btn_form">Submit</button>
</div>
<div id="div_form2">
<input type = "text" id="txt_lname" name="txt_lname"/>
<select id="opt_sel" name="kindly select the value">
<option>
Select
</option>
<option>
Bananana
</option>
</select>
<button id="btn_form1">Submit</button>
</div>
</form>
<form id="form2" name="form2" method="post">
<div id="div_form3">
<input type = "text" id="txt_mname" name="txt_mname" />
<button id="btn_form3">Submit</button>
</div>
</form>
CSS
.error_field{
background-color:red;
color:black;
border:1px solid red;
}
jquery
$("#div_form2").hide();
$("#div_form3").hide();
$("#form1,").validate({
rules:{
txt_fname:{
required:true
}
},
messages :{
txt_fname:"Fill this field"
}
});
使用此代码,第二个表单被隐藏,第一个表单正在验证,但选项选择字段没有验证:(一旦值或输入它没有提交,也没有显示 form2。请帮助我,因为我是新手对于 jquery,我在这里很挣扎
这是小提琴Link
提前致谢。
感谢和问候 马哈迪文
【问题讨论】:
标签: javascript jquery css validation