- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要制作一个带有验证的多步骤表单。多步按钮可以正常工作,我可以提交表单,但表单未得到验证。它只验证多步骤表单中的最后一页,但我想在每次按下“下一步”按钮之前验证字段。
Html代码:
<form name="basicform" id="basicform" method="post"
action="yourpage.html">
<!-- id will be unique, but class name will be same -->
<div id="sf1" class="frm">
<fieldset>
<legend>Step 1 of 3</legend>
<div class="form-group">
<label class="col-lg-2 control-label" for="uname">Your Name:
</label>
<div class="col-lg-6">
<input type="text" placeholder="Your Name" id="uname"
name="uname" class="form-control" autocomplete="off">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- open1 is given in the class that is binded with the
click event -->
<button class="btn btn-primary open1" type="button">Next
<span class="fa fa-arrow-right"></span></button>
</div>
</div>
</fieldset>
</div>
<!-- id will be unique, but class name will be same -->
<div id="sf2" class="frm">
<fieldset>
<legend>Step 2 of 3</legend>
<div class="form-group">
<label class="col-lg-2 control-label" for="uemail">Your
Email: </label>
<div class="col-lg-6">
<input type="text" placeholder="Your Email" id="uemail"
name="uemail" class="form-control" autocomplete="off">
</div>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- back2 unique class name -->
<button class="btn btn-warning back2" type="button"><span
class="fa fa-arrow-left"></span> Back</button>
<!-- open2 unique class name -->
<button class="btn btn-primary open2" type="button">Next
<span class="fa fa-arrow-right"></span></button>
</div>
</div>
</fieldset>
</div>
<!-- id will be unique, but class name will be same -->
<div id="sf3" class="frm">
<fieldset>
<legend>Step 3 of 3</legend>
<div class="form-group">
<label class="col-lg-2 control-label" for="upass1">Password:
</label>
<div class="col-lg-6">
<input type="password" placeholder="Your Password"
id="upass1" name="upass1" class="form-control" autocomplete="off">
</div>
</div>
<div class="form-group">
<label class="col-lg-2 control-label" for="upass1">Confirm
Password: </label>
<div class="col-lg-6">
<input type="password" placeholder="Confirm Password"
id="upass2" name="upass2" class="form-control" autocomplete="off">
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- Unique class name -->
<button class="btn btn-warning back3" type="button"><span
class="fa fa-arrow-left"></span> Back</button>
<!-- Unique class name -->
<button class="btn btn-primary open3" type="button">Submit
</button>
<img src="spinner.gif" alt="" id="loader" style="display:
none">
</div>
</div>
</fieldset>
</div>
</form>
JavaScript/Jquery 代码:
//validation
<script type="text/javascript" src="jquery.validate.js"></script>
<script type="text/javascript">
jQuery().ready(function() {
var v = jQuery("#basicform").validate({
rules: {
uname: {
required: true,
minlength: 2,
maxlength: 16
},
uemail: {
required: true,
minlength: 2,
email: true,
maxlength: 100,
},
upass1: {
required: true,
minlength: 6,
maxlength: 15,
},
upass2: {
required: true,
minlength: 6,
equalTo: "#upass1",
}
},
errorElement: "span",
errorClass: "help-inline",
});
});
//navigation
jQuery().ready(function() {
// Binding next button on first step
$(".open1").click(function() {
if (v.form()) {
$(".frm").hide("fast");
$("#sf2").show("slow");
}
});
// Binding next button on second step
$(".open2").click(function() {
if (v.form()) {
$(".frm").hide("fast");
$("#sf3").show("slow");
}
});
// Binding back button on second step
$(".back2").click(function() {
$(".frm").hide("fast");
$("#sf1").show("slow");
});
// Binding back button on third step
$(".back3").click(function() {
$(".frm").hide("fast");
$("#sf2").show("slow");
});
$(".open3").click(function() {
if (v.form()) {
// optional
// used delay form submission for a seccond and show a loader
image
$("#loader").show();
setTimeout(function(){
$("#basicform").html('<h2>Thanks for your time.</h2>');
}, 1000);
// Remove this if you are not using ajax method for submitting
values
return false;
}
});
});
</script>
最佳答案
您在单独的 jQuery().ready block 中声明表单“v”,因此第二个 jQuery().ready block 未检测到“v”。像这样将它们合并成一个 block :
$(document).ready(function() {
var v = $("#form1").validate({
rules: {
fname: {
required: true,
minlength: 2,
maxlength: 16
},
lname: {
required: true,
minlength: 2,
email: true,
maxlength: 100,
},
prnum: {
required: true,
minlength: 6,
maxlength: 15,
},
age: {
required: true,
minlength: 6,
}
},
errorElement: "span",
errorClass: "help-inline",
});
// Binding next button on first step
$(".frm").hide("fast");
$("#sf1").show("slow");
$(".open1").click(function() {
if (v.form()) {
$(".frm").hide("fast");
$("#sf2").show("slow");
}
});
// Binding next button on second step
$(".open2").click(function() {
if (v.form()) {
$(".frm").hide("fast");
$("#sf3").show("slow");
}
});
$(".open3").click(function() {
$(".frm").hide("fast");
$("#sf4").show("slow");
});
// Binding back button on second step
$(".back2").click(function() {
$(".frm").hide("fast");
$("#sf1").show("slow");
});
// Binding back button on third step
$(".back3").click(function() {
$(".frm").hide("fast");
$("#sf2").show("slow");
});
$(".back4").click(function() {
$(".frm").hide("fast");
$("#sf3").show("slow");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.16.0/jquery.validate.min.js"></script>
<form id="form1" name="form1" action="saveDoc.html" method="post">
<h1 style="color:#000">New Doctor Registration</h1>
<br>
<div id="sf1" class="frm">
<!-- user name field will be here with next button -->
<fieldset>
<div class="col-xs-1"></div>
<font size="5" color="#009999">Step 1 of 4</font>
<hr style="border: 1px solid #cccccc">
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Doctor Id <span>*</span></p>
<input type="text" name="docID" id="docID" class="form-control input-sm" required />
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Date of Join <span>*</span></p>
<input type="date" name="doj" id="doj" max="3000-12-31" class="form-control input-sm" required />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Registration Number<span>*</span></p>
<input type="text" name="prnum" id="prnum" class="form-control input-sm" />
</div>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Employment Type <span>*</span></p>
<select class="form-control" name="etype" id="etype" required>
<option default selected>Select Employment Type</option>
<option>Permanent</option>
<option>Temporary</option>
<option>Visiting</option>
</select>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Preferred Shift <span>*</span></p>
<select class="form-control" name="shift" id="shift" required>
<option default selected>Select Shift</option>
<option>Morning</option>
<option>Afternoon</option>
<option>Evening</option>
<option>Night</option>
</select>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Department <span>*</span></p>
<select class="form-control" name="department" id="department">
<option default selected>Select Department</option>
<option>Cardiology</option>
<option>Critical Care</option>
<option>General Surgery</option>
</select>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Designation <span>*</span></p>
<select class="form-control" name="designation" id="designation">
<option default selected>Select Designation</option>
<option> Doctor of Dental Surgery</option>
<option>Doctor of Psychology</option>
</select>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- open1 is given in the class that is binded with the click event -->
<center>
<button class="btn btn-primary open1" name="button1" id="button1" type="button">Next <span class="fa fa-arrow-right"></span></button>
</center>
</div>
</div>
</fieldset>
</div>
<!-- id will be unique, but class name will be same -->
<div id="sf2" class="frm">
<!-- user email field will be here with next and previous button -->
<fieldset>
<div class="col-xs-1"></div>
<font size="5" color="#009999">Step 2 of 4</font>
<hr style="border: 1px solid #cccccc">
<center><b><font size="3">Personal Details</font></b></center>
<br>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>First Name <span>*</span></p>
<input type="text" name="fname" id="fname" class="form-control input-sm" required />
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Middle Name <span></span></p>
<input type="text" name="mname" id="mname" class="form-control input-sm" />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Last Name <span>*</span></p>
<input type="text" name="lname" id="lname" class="form-control input-sm" required/>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Date of Birth <span>*</span></p>
<input type="text" name="dob" id="dob" max="3000-12-31" value="2012-05-15 21:05" class="form-control input-sm" required/>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Age <span>*</span></p>
<input type="number" name="age" id="age" maxlength="3" class="form-control input-sm form_datetime" required/>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<div class="btn-group" data-toggle="buttons">
<p>Gender <span>*</span></p>
<label class="btn btn-default">
<input class="form-control input-sm" style="width: 10px;" value="M" type="radio" name="gender" />M</label>
<label class="btn btn-default">
<input class="form-control input-sm" type="radio" value="F" name="gender" />F</label>
<label class="btn btn-default">
<input class="form-control input-sm" type="radio" value="Transgender" name="gender" />Transgender</label>
</div>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>SSN <span>*</span></p>
<input type="text" name="ssn" id="ssn" class="form-control input-sm" required/>
</div>
</div>
<div class="col-xs-4">
</div>
<div class="col-xs-3">
</div>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- back2 unique class name -->
<center>
<button class="btn btn-warning back2" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<!-- open2 unique class name -->
<button class="btn btn-primary open2" type="button">Next <span class="fa fa-arrow-right"></span></button>
</center>
</div>
</div>
</fieldset>
</div>
<!-- id will be unique, but class name will be same -->
<div id="sf3" class="frm">
<!-- user email field will be here with next and previous button -->
<fieldset>
<div class="col-xs-1"></div>
<font size="5" color="#009999">Step 3 of 4</font>
<hr style="border: 1px solid #cccccc">
<center><b><font size="3">Contact Details</font></b></center>
<br>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>LandPhone <span>*</span></p>
<input type="text" name="landphone" id="landphone" value="080-" maxlength="11" class="form-control input-sm" required />
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Mobile<span>*</span></p>
<input type="text" name="mobile" id="mobile" value="+91" maxlength="14" class="form-control input-sm" required />
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Email <span>*</span></p>
<input type="email" name="email" id="email" class="form-control input-sm" required />
</div>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Address1<span>*</span></p>
<textarea name="address" id="address1" rows="5" data-rule="required" data-msg="address1" required></textarea>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>Address2<span></span></p>
<textarea name="address2" id="address2" rows="5" data-rule="required" data-msg="address2"></textarea>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Country <span>*</span></p>
<select class="form-control" name="country" id="country" required>
<option>Select Country</option>
<option>India</option>
</select>
</div>
</div>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>State <span>*</span></p>
<select class="form-control" name="state" id="state" required>
<option>Select State</option>
<option>Karnataka</option>
</select>
</div>
</div>
<div class="col-xs-4">
<div class="form-group">
<p>City <span>*</span></p>
<select class="form-control" name="city" id="city" required>
<option>Select City</option>
<option>Bangalore</option>
</select>
</div>
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Postal Code<span>*</span></p>
<input type="text" name="pcode" maxlength="6" id="pcode" class="form-control input-sm" required />
</div>
</div>
</div>
<div class="clearfix" style="height: 10px;clear: both;"></div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- back2 unique class name -->
<center>
<button class="btn btn-warning back3" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<!-- open2 unique class name -->
<button class="btn btn-primary open3" type="button">Next <span class="fa fa-arrow-right"></span></button>
</center>
</div>
</div>
</fieldset>
</div>
<div id="sf4" class="frm">
<!-- user email field will be here with next and previous button -->
<fieldset>
<div class="col-xs-1"></div>
<font size="5" color="#009999">Step 4 of 4</font>
<hr style="border: 1px solid #cccccc">
<center><b><font size="3">Education Details</font></b></center>
<br>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<div class="form-group">
<p>Qualification <span>*</span></p>
<input type="text" name="qualification" id="qualification" class="form-control input-sm" required>
</div>
</div>
<div class="col-xs-4">
</div>
<div class="col-xs-3">
<div class="form-group">
<p>Specialization <span>*</span></p>
<input type="text" name="specialization" id="specialization" class="form-control input-sm" required/>
</div>
</div>
</div>
<div class="form-group">
<div class="col-lg-10 col-lg-offset-2">
<!-- Unique class name -->
<center>
<button class="btn btn-warning back4" type="button"><span class="fa fa-arrow-left"></span> Back</button>
<!-- Unique class name -->
<button type="submit" class="btn btn-primary open4 ">Save</button>
</center>
</div>
</div>
</fieldset>
</div>
<div class="form-group row">
<div class="col-xs-1"></div>
<div class="col-xs-3">
<!-- <div class="form-group">
<p>Department <span>*</san></p>
<select class="form-control" name="dept" id="dept" required>
<option>Select Department</option>
<option>OPD</option>
<option>Cardiology</option>
<option>Critical Care</option>
</select>
</div>
-->
</div>
<div class="col-xs-4">
</div>
<div class="col-xs-3">
</div>
</div>
<button type="" class="bouton-contact" onclick=""></button>
</form>
关于javascript - 表单验证不适用于多步骤表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44527657/
我是在项目中使用 keras 的新手。我一直在我的模型中使用generator。 我真的很困惑我应该输入什么值 1) In fit_generator : steps_per_epoch & vali
假设我们有如下情况: A has to give $10 to B. B has to give $20 to C. C has to give $10 to D. 现在这种情况可以简化为: A lo
我正在尝试对特定列(在工作表“OA”中)进行相对引用,我需要在 110 的步骤中检索新工作表中的单元格内容 例如, =OA!$AB217 =OA!$AB327 =OA!$AB437 与其在每个单元格中
我的 PowerShell 控制台启动时间很慢(总是等待超过 5 秒),并且希望获得有关故障排除步骤的建议,以找出瓶颈可能在哪里? 我已经阅读了关于运行脚本的内容,-NoProfile防止模块等加载很
我在 NativeScript 应用程序中使用 slider 小部件,我想知道是否有步骤属性。在我的例子中,小部件代表金钱,我希望以 5 美元的增量滑动。 我查看了文档,但找不到任何对这种情况有帮助的
我在 NativeScript 应用程序中使用 slider 小部件,我想知道是否有步骤属性。在我的例子中,小部件代表金钱,我希望以 5 美元的增量滑动。 我查看了文档,但找不到任何对这种情况有帮助的
这是我的code : &n
为什么 (2) c.ERR(模棱两可)?第一个方法参数 - char ('a') 被扩展为 float => 匹配。 如果找到匹配项,是否无需继续执行第 2 步(装箱/拆箱)或第 3 步(尝试可变参数
我有一个函数,它处理一个包含 6100 个列表项的列表。当列表只有 300 个项目时,该代码可以正常工作。但是立即与 6100 崩溃。有没有一种方法可以遍历这 6100 个项目,一次说 30 个,然后
1.制作PHP安装程序的原理 其实PHP程序的安装原理无非就是将数据库结构和内容导入到相应的数据库中,从这个过程中重新配置连接数据库的参数和文件,为了保证不被别人恶意使用安装文件,当安装
我创建了一个类似于 primeNG page 的步骤组件我想把他放在一个 dynamic dialog 里面但在应用它之后,“第 1 步”和“第 2 步”不会呈现。 查看代码,我发现关键部分是我们打开
我在理解描述的 MixColumns 步骤时遇到问题 here . 我知道扩散,这一切都是有道理的,因为它指出每列都被视为多项式并乘以 GF(2^8) 的模。 但是..乘以GF(2 ^ 8)。尽管域仍
根据我对 TeamCity 工作原理的观察,我注意到在所有步骤执行完毕后评估构建失败条件。这很烦人,因为如果满足任何构建失败条件,我不能有一个不会执行的步骤。 我不是指常见的构建失败条件,例如“至少一
基于这篇试图在我的环境中测试管道代码的帖子。但它给出了以下错误消息。如何修复他的管道代码? ERROR: Unable to find project for artifact copy: test
我参与了一个项目,需要向我的一位同事提供生产数据的子集(日期范围),以进行故障排除。我想将经过清理的生产数据子集插入新的数据库表中我的同事可以访问。请提出实现此目标的最佳方法。 最佳答案 最简单的方法
我有这样的场景: 鉴于我去这个页面 当我输入 cucumber 时 然后我点击 然后我应该看到文字 我不应该看到这条线 如果我运行这个场景,它将执行所有 5 个步骤。但是我想跳过第4步(然后我应该看到
是否有任何功能可以避免 m 文件的绘图输出? 我的意思是我在文件的开头放置了一个函数(如 clc),然后所有绘图函数都被阻止。 最佳答案 您可以使用自己的(嵌套在您的函数内或同一目录中)重载内置绘图函
我是小 cucumber 语言的新手,这在我看来是非常基本的问题,但我找不到答案。 我知道可以在 Gherking 中编写多行步骤参数,如下所示: Given a blog post named "R
即使其中一个步骤失败,有没有办法继续执行 Cucumber Steps。在我当前的设置中,当一个步骤失败时, cucumber 会跳过剩余的步骤......我想知道是否有某种方法可以设置 cucumb
start-step-stop 码是一种数据压缩技术,用于压缩相对较小的数字。 该代码的工作原理如下:它具有三个参数,start、step 和 stop。 Start 确定用于计算前几个数字的位数。
我是一名优秀的程序员,十分优秀!