我有 2 个字段需要验证,如果它们显示在屏幕上。当表单最初加载时,它们是隐藏的,除非从下拉框中选择项目,否则它们将保持隐藏状态。选择值后,将出现 2 个字段,然后验证正常工作。但是,如果选择了另一个不会使这两个字段出现的值,则它们仍在验证中并且不允许页面提交。关于如何实现这一目标的任何想法?
function DisplayOutageDates() {
if ($('#ddImpact').val() == "Service Affecting") {
$('#outageDates').css('display','');
document.getElementById('txtOutageStartDate').Visible = true;
document.getElementById('RFVOutageStartDate').Visible = true;
} else {
$('#outageDates').css('display','none');
document.getElementById('txtOutageStartDate').Visible = false;
document.getElementById('RFVOutageStartDate').Visible = false;
}
}
<asp:RequiredFieldValidator ID="RFVOutageStartDate" runat="server"
ControlToValidate="txtOutageStartDate" SetFocusOnError="true"
ErrorMessage="Please enter the Outage Start Date" />