JavaScript 错误:“window.top.document.getElementById(...)”为 null 或不是对象

发布于 2024-12-03 09:50:50 字数 1768 浏览 1 评论 0原文

当我尝试单击日历控件时,出现 JavaScript 错误。

html 代码是:

        <td align="left" style="width:50%;"><asp:Label runat="server" CssClass="TextFontBold" ID="lblStartDate" Text="Start Date:"></asp:Label>
            <input type="text" class="TextBox" id="FromDate" runat="server"/><a href="javascript:ShowCalendar('FromDate1')"><img src="images/Calendar.png" border="0" /></a>
            <iframe src="Calendar.aspx?DateTextID=FromDate" style="display:none; top: 0px; left: 0px; width:245px; height:164px" frameborder="0" scrolling="no" name="FromDate1" id="FromDate1"></iframe>&nbsp;&nbsp;&nbsp;&nbsp;
            &nbsp;&nbsp;&nbsp;&nbsp;<asp:Label runat="server" CssClass="TextFontBold" ID="lblPromoStartTime" Text="Start Time:"></asp:Label>
        </td>  

当我单击日历控件中的日期时,会在代码隐藏中执行此代码:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
    Dim strjscript As String = "<script language=""javascript"" type=""text/javascript"">"
    strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "').value = '" & Calendar1.SelectedDate & "';"
    strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "1').style.display = 'none';"
    strjscript = strjscript & "</script" & ">"
    Literal1.Text = strjscript
End Sub  

我收到的错误是 'window.top.document.getElementById (...)' 为 null 或不是对象

我确实有一个名为 FromDate 的对象。
还有什么可能导致此错误?

I am getting a javascript error when I attempt to click on my calendar control.

The html code is:

        <td align="left" style="width:50%;"><asp:Label runat="server" CssClass="TextFontBold" ID="lblStartDate" Text="Start Date:"></asp:Label>
            <input type="text" class="TextBox" id="FromDate" runat="server"/><a href="javascript:ShowCalendar('FromDate1')"><img src="images/Calendar.png" border="0" /></a>
            <iframe src="Calendar.aspx?DateTextID=FromDate" style="display:none; top: 0px; left: 0px; width:245px; height:164px" frameborder="0" scrolling="no" name="FromDate1" id="FromDate1"></iframe>    
                <asp:Label runat="server" CssClass="TextFontBold" ID="lblPromoStartTime" Text="Start Time:"></asp:Label>
        </td>  

When I click on a date in the calendar control, this code is executed on the code-behind:

Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
    Dim strjscript As String = "<script language=""javascript"" type=""text/javascript"">"
    strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "').value = '" & Calendar1.SelectedDate & "';"
    strjscript &= "window.top.document.getElementById('" & HttpContext.Current.Request.QueryString("DateTextID") & "1').style.display = 'none';"
    strjscript = strjscript & "</script" & ">"
    Literal1.Text = strjscript
End Sub  

The error I am getting is 'window.top.document.getElementById(...)' is null or not an object

I do have an object called FromDate.
What else could be causing this error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱的十字路口 2024-12-10 09:50:50

尝试用 window.parent.document.getElementById() 而不是 window.top.document.getElementById()

Try window.parent.document.getElementById() instead of window.top.document.getElementById()

遥远的她 2024-12-10 09:50:50

您是否尝试过parent.document.getElementById(...)?只是一个想法...

按照 pimvdb 的建议进行编辑

Have you tried parent.document.getElementById(...)? Just an idea...

Edited as suggested by pimvdb

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文