我遇到了 jQuery Validator 插件和单选按钮的问题。我有一组三个"lookingfor"
单选按钮......我想确保至少有一个被选中。尽管无论我做什么,我仍然会收到“此字段为必填项”的消息。有任何想法吗?
<html>
<body>
<form action="#" id="signupform" method="post">
<label for="lookingfor" class="error"></label>
<fieldset name="lookingfor">
<input type="radio" name="lookingfor" value="female"/>
<label for="female"><div class="sprite female" ></div></label>
<input type="radio" name="lookingfor" value="male" />
<label for="male"><div class="sprite male"></div></label>
<input type="radio" name="lookingfor" value="other" />
<label for="other"><div class="sprite other"></div></label>
</fieldset>
<input type="submit" id="submit" value="" />
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.0/jquery.validate.js" type="text/javascript"></script>
<script>
jQuery(document).ready(function() {
jQuery("#signupform").validate({
rules: {
lookingfor:{ required: true }
}
});
});
</script>
</body>
</html>