我有一个表单,当用户单击“是”时显示详细问题,并在用户单击“否”时隐藏它。我目前拥有它,因此如果他们单击“是”,则需要详细说明问题。我的问题是,如果他们单击“是”然后单击“否”,无论我尝试什么,验证功能都不会清除。他们必须再次单击“是”并在文本区域中输入一些内容才能实际提交表单。我已经尝试了所有方法(jQuery 取消绑定、清除、删除和更改),但没有成功。我希望他们能够对他们的内心内容单击是和否,并且只有在他们的最终选择为“是”时才需要额外的文本区域。所以我需要它能够清除下的具体验证功能$('#1yes').click(function () {
,激活$('#affirmative1').show(1000);
时不清除。$('#1no').click(function () {
提前谢谢你,蔡斯
这是jQuery:
$('#1yes').click(function () {
if ($('#1yes').is(':checked')) {
$('#affirmative1').show(1000);
$(function validation() {
$('#myform').ipValidate({
required: { //required is a class
rule: function () {
return $(this).val() == '' ? false : true;
},
onError: function () {
if (!$(this).parent().hasClass('element_container')) {
$(this).wrap('<div class="element_container error_div"></div>').after('<span>' + $(this).attr('rel') + '</span>');
} else if (!$(this).parent().hasClass('error_div')) {
$(this).next().text($(this).attr('rel')).parent().addClass('error_div');
}
//alert('Form is ready for submit.');
},
onValid: function () {
$(this).next().text('').parent().removeClass('error_div');
$(this).focus();
}
},
});
});
}
});
$('#1no').click(function () {
if ($('#1no').is(':checked')) { $('#affirmative1').hide(1000);
//code to clear "validation" function
}
});
这是HTML:
<div class="radio single_form_element">
<div class="chk_div">
<p>
<label>1) Do you have some involvement or financial interest that is, or could be perceived to be, in conflict with the proper discharge of your duties at the
University?</label><br>
<input type="radio" name="response1" value="yes" id="1yes" required>yes<br>
<input type="radio" name="response1" value="no" id="1no" required>no
</p>
<div id="affirmative1" style="display:none; margin:0 4% 0 4%;">
<fieldset>
<p>
<label>Describe the University-administered project and your involvement, also include information about federally-funded projects you are working on that could reasonably be affected by an outside financial interest:</label><br>
<textarea name="comments1a" class="input_border input_width required" rel="Enter more info here!"></textarea>
</p>
</fieldset>
</div>
</div><!-- End CHK_DIV -->
</div><!-- END SINGLE FORM ELEMENT(RADIO) -->