我有一个窗体,当用户单击“是”时显示详细问题,并在用户单击“否”时隐藏它。我现在拥有它,所以如果他们点击“是”,则需要阐述问题。我的问题是,如果他们点击“是”然后点击“否”,验证功能将不会清除,无论我尝试什么。他们必须再次单击“是”,然后在textarea中输入某些内容以便表单实际提交。我已经尝试了一切(jQuery解除绑定,清除,删除和更改)以无效为准。我希望他们能够在他们的心中点击“是”和“否”,并且如果他们的最终选择是“是”,则只需要额外的textarea。所以我需要它能够清除$('#1yes').click(function() {
下的特定验证功能,而在激活$('#1no').click(function() {
时不会清除$('#affirmative1').show(1000);
。谢谢你在前进, 大通清除“no”选择的详细验证功能。在“是”选择时重新启动功能
这里是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) -->
努力帮助却无插件' ipValidate'来自。在jsfiddle.net中的演示复制问题将是一个很大的帮助 – charlietfl
如您所请求:http://jsfiddle.net/RrzN6/2/ –
您是否反对更改验证插件?使用jQuery验证更简单。少得多的代码来创建。大量使用,并有良好的文档和支持 – charlietfl