Javascript 如何通过字段集循环检查控件是否为空或未选择值?
目前,我有多个字段集5,但会不断增加,我希望在每个字段集中的每个元素之间循环以进行验证: 输入/文本区域文本框:检查是否为空 选择下拉菜单:检查值是否为0 以下是我的3个字段集:Javascript 如何通过字段集循环检查控件是否为空或未选择值?,javascript,jquery,Javascript,Jquery,目前,我有多个字段集5,但会不断增加,我希望在每个字段集中的每个元素之间循环以进行验证: 输入/文本区域文本框:检查是否为空 选择下拉菜单:检查值是否为0 以下是我的3个字段集: <!-- fieldsets --> <fieldset style="max-width:400px;"> <h2 class="fs-title">Create your account</h2> <h3 class="fs-subtit
<!-- fieldsets -->
<fieldset style="max-width:400px;">
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">Step 1</h3>
@Html.TextBoxFor(m => m.Email, new { @type = "email",@id = "email", @name = "email", @placeholder="Email", @required = "*", @class = "form-control input-lg" })
@Html.ValidationMessageFor(m => m.Email, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.Password, new { @type = "password", @class = "form-control input-lg", @id = "password", @placeholder="Password", @required = "*" })
@Html.ValidationMessageFor(m => m.Password, "", new { @class = "text-danger" })
@Html.TextBoxFor(m => m.ConfirmPassword, new { @type = "password", @class = "form-control input-lg", @id = "confirmpassword", @placeholder = "Confirm Password", @required = "*" })
@Html.ValidationMessageFor(m => m.ConfirmPassword, "", new { @class = "text-danger" })
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset style="max-width:400px;">
<h2 class="fs-title">Upload your CV</h2>
<h3 class="fs-subtitle">Step 2</h3>
<input type="file" name="file" placeholder="Upload file" />
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
<fieldset style="max-width:400px;">
<h2 class="fs-title">Personal Details</h2>
<h3 class="fs-subtitle">Step 3</h3>
<input type="text" name="fname" placeholder="First Name" required />
<input type="text" name="lname" placeholder="Last Name" />
<input type="text" id="dob" name="dob" placeholder="Date of Birth" />
<input type="text" name="phone" placeholder="Mobile Number" />
@*<textarea name="address" placeholder="Address"></textarea>*@
<input type="button" name="previous" class="previous action-button" value="Previous" />
<input type="button" name="next" class="next action-button" value="Next" />
</fieldset>
谢谢您的帮助。单击“下一步”按钮后,您可以尝试验证
$(".next").click(function(){
$("fieldset").children().not("h2, h3, button").each(function(){
if(!$(this).val()){
alert("Empty!!")
}
})
})
要跳过不需要验证的元素,请使用not。谢谢。这就是我想要它做的。感谢您的帮助!
$(".next").click(function(){
$("fieldset").children().not("h2, h3, button").each(function(){
if(!$(this).val()){
alert("Empty!!")
}
})
})