簡體   English   中英

ASP.NET 2.0自定義客戶端驗證在Internet Explorer中不起作用

[英]ASP.NET 2.0 Custom Client Side Validation not working in Internet Explorer

我有兩個文本框,一個用於預定日期,另一個用於預定時間。 如果兩個文本框都為空白,或者兩個都有內容,我想通過驗證。 如果只有一個內容,我想通過驗證。 一切都在服務器端正常運行,並且以下客戶端代碼在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中將其破壞,然后再次嘗試進入,它將再次中斷,但是如果我嘗試再次進入它,則它將再次運行,並且驗證正常進行。

任何人都可以對此有所了解嗎?

你可以這樣使用

ctl00_MainContent_txtScheduledTime並非javascript變量,除非您使用進行了初始化

var ctl00_MainContent_txtScheduledTime = document.getElementById('<%=txtScheduledTime.ClientID%>');

或者你可以像

(document.getElementById('<%=txtScheduledTime.ClientID%>').value!="" || document.getElementById('<%=txtScheduledDate.ClientID%>').value!="" )

問候。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM