表单的jQuery验证规则有问题
您好,我正在尝试使用jQuery验证 基本上我有一个表单,在这里,不管发生什么,都需要某些元素 但我还有其他字段,只有选中复选框时才需要 我正在使用jQuery验证 这里有一个链接 这是我的表格表单的jQuery验证规则有问题,jquery,html,forms,validation,Jquery,Html,Forms,Validation,您好,我正在尝试使用jQuery验证 基本上我有一个表单,在这里,不管发生什么,都需要某些元素 但我还有其他字段,只有选中复选框时才需要 我正在使用jQuery验证 这里有一个链接 这是我的表格 <form action="http://www.funnytennisstories.com/save-story.php" method="POST" name="story-form" id="storyForm"> <fieldset> <label for
<form action="http://www.funnytennisstories.com/save-story.php" method="POST" name="story-form" id="storyForm">
<fieldset>
<label for="Your Story">Your Story</label>
<textarea class="required" name="your-story" cols="" rows=""></textarea>
<label for="free-wrist-band">Check the box to receive a free tennis wristband </label>
<input id="free-wrist-band-check-box" name="free-wrist-band" type="checkbox" />
<label for="address">Address</label><input id="address" class="txtClass shipping" name="address" type="text" >
<input type="submit" name="story-post" value="Post Your Story"/>
</fieldset>
</form>
chrome上的firebug lite(和inspect元素工具)和safari上的inspector中也没有显示调试
任何想法都可以添加到$(document.ready(function(){…})
因此,只有选中了复选框
,才需要地址文本框
您使用什么表单验证jQuery扩展?(谷歌给了我很多“jQuery验证”的结果。)或者你想写你自己的验证工具吗?编辑了这篇文章,靠近顶部
<script>
$(document).ready(function(){
$("#storyForm").validate({
debug:true,
rules: {
shipping: {
required: $("#free-wrist-band-check-box:checked")
}
}
});
});
$('#free-wrist-band-check-box').on('change', function(){
if($(this).is(':checked')) $("#address").rules("add", "required");
else $("#address").rules("remove", "required");
});