使用 jQuery 验证编写条件规则
您好,我有一个简单的模式弹出窗口,其中有 3 个名称字段和 3 个彼此相邻的电子邮件字段。 我是 jQuery 新手,所以有人可以帮助我如何为以下情况编写逻辑吗?
名字字段和电子邮件字段是必填字段,因此我将类保留为必填字段,但其他两个姓名和电子邮件字段是可选的,但如果我在姓名字段中输入值,则必须在电子邮件字段中输入值。 换句话说,如果姓名字段不为空,则电子邮件字段不应为空。 请告诉我是否有人可以帮助我,谢谢。
<div class="leftCol">
<label for="emailToName1" class="formLabel"><span class="required">*</span>Name:</label>
<div><input type="text" id="emailToName1" name="referName01" value="${referAFriendBean.referName01!}" class="required" tabindex="1" /></div>
<div class="pad5Top"><input type="text" id="emailToName2" name="referName02" value="${referAFriendBean.referName02!}" tabindex="3" /></div>
<div class="pad5Top"><input type="text" id="emailToName3" name="referName03" value="${referAFriendBean.referName03!}" tabindex="5" /></div>
</div>
<div class="rightCol">
<label for="emailToAddress1" class="formLabel"><span class="required">*</span>Email address:</label>
<div><input type="text" id="emailToAddress1" name="referEmail01" value="${referAFriendBean.referEmail01!}" class="required email" tabindex="2" /></div>
<div class="pad5Top"><input type="text" id="emailToAddress2" name="referEmail02" class="email" tabindex="4" value="${referAFriendBean.referEmail02!}" /></div>
<div class="pad5Top"><input type="text" id="emailToAddress3" name="referEmail03" class="email" tabindex="6" value="${referAFriendBean.referEmail03!}" /></div>
</div>
</div>
Hi I have a simple modal popup which has 3 name fields and 3 e mail fields adjacent to each other. I am new to jQuery so can any one please help me how to write a logic for the following case?
The first name field and Email field are mandatory so I kept the class as required fields but the other two name and e-mail fields are optional but if I enter a value in name field I have to enter the value in Email field. In other words if name field is not empty email field should not be empty. Please let me know if some one can help me thank you.
<div class="leftCol">
<label for="emailToName1" class="formLabel"><span class="required">*</span>Name:</label>
<div><input type="text" id="emailToName1" name="referName01" value="${referAFriendBean.referName01!}" class="required" tabindex="1" /></div>
<div class="pad5Top"><input type="text" id="emailToName2" name="referName02" value="${referAFriendBean.referName02!}" tabindex="3" /></div>
<div class="pad5Top"><input type="text" id="emailToName3" name="referName03" value="${referAFriendBean.referName03!}" tabindex="5" /></div>
</div>
<div class="rightCol">
<label for="emailToAddress1" class="formLabel"><span class="required">*</span>Email address:</label>
<div><input type="text" id="emailToAddress1" name="referEmail01" value="${referAFriendBean.referEmail01!}" class="required email" tabindex="2" /></div>
<div class="pad5Top"><input type="text" id="emailToAddress2" name="referEmail02" class="email" tabindex="4" value="${referAFriendBean.referEmail02!}" /></div>
<div class="pad5Top"><input type="text" id="emailToAddress3" name="referEmail03" class="email" tabindex="6" value="${referAFriendBean.referEmail03!}" /></div>
</div>
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许是这样的:
您还可以检查每个值的长度。
Perhaps something like this:
You could also check the length of each value.