我有两个文本框,一个用于预定日期,另一个用于预定时间。如果两个文本框都是空白的,或者都有内容,我想通过验证。如果只有一个有内容,我想验证失败。服务器端一切正常,以下客户端代码在 Chrome 中正常工作。
function CheckScheduledDateTime(sender, args) {
if (ctl00_MainContent_txtScheduledTime.value!="" || ctl00_MainContent_txtScheduledDate.value!="" )
{
if (ctl00_MainContent_txtScheduledTime.value!="" && ctl00_MainContent_txtScheduledDate.value=="")
{
args.IsValid=false;
alert("Scheduled date is required");
}
else if (ctl00_MainContent_txtScheduledTime.value=="" && ctl00_MainContent_txtScheduledDate.value1!="")
{
args.IsValid=false;
alert("Scheduled time is required");
}
else
{
args.IsValid=true;
}
}
else
{
args.IsValid = true;
}
}
在 Internet Explorer 中,它不起作用,并且我收到以下错误:
“Microsoft JScript 运行时错误:'ctl00_MainContent_txtScheduledTime' 未定义”
奇怪的是,它在 Visual Studio 中被破坏了,如果我再次尝试进入,它会再次中断,但是如果我第三次尝试进入它,它会运行,并且验证工作正常。
有人能对此有所了解吗?