有一个基于无线电隐藏/可见的字段。
因此,在加载页面时,我们根据无线电值使其可见隐藏
$(document).ready(function() {
if(edit) {
populateData();
}
$(radio).change(function(){
//here also we show hide text box based on radio value
})
function PopulateData() {
//This does select radio and based on same show / hide text field
}
$("myForm").validate(); // attaching validate . At this point field could be hidden or visible
$(savebutton).click(function(){
/*This does not validate text
field (visibleBasedOnRadio) which was hidden and made visible by either of above */
if( $("myForm").valid() == false) {
return false;
}
});
});
<form id="myForm">
<radio>
<option 1>
<option 2>
</radio>
<input type="text" id="visibleBasedOnRadio" class="required" style="display:none"/>
</form>