我有一个隐藏/显示 div 的单选按钮。所有可见元素都是“必需的”,但在验证规则之后添加忽略:“:隐藏”,不起作用......这是代码:
<script type="text/javascript">
$(document).ready(function(){
$("#myForm").validate({
rules: {
name: "required",
age: "required",
height: "required",
ignore: ":hidden"
}
})
});
</script>
</head>
<body>
<form id="myForm" name="myForm" method="post" action="" >
<input type="radio" name="checkAge" value="adult" onclick="$('#minorRequisites').hide();" />Adult<br/>
<input type="radio" name="checkAge" value="minor" onclick="$('#minorRequisites').show()" checked="checked"/>Child<br/>
Name <input id="name" name="name" type="text" /><br/>
<div id="minorRequisites">
Age <input id="age" name="age" type="text" /><br/>
Height <input id="height" name="height" type="text" /><br/>
</div>
<input type="submit" />
</form>
</body>
如果选中“成人”,我希望能够提交仅提供姓名的表格......有什么想法吗?:)