隐藏DIV的javascript函数无法正常工作 [英] javascript function to hid DIV not working correctly

查看:77
本文介绍了隐藏DIV的javascript函数无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨-我希望有人可以解决我遇到的这个问题,我已经创建了DIV并将显示设置为无",因此在页面加载中,DIV中的所有内容都被隐藏了.但是,当我单击一个按钮时,我想显示DIV,然后再次单击该按钮以隐藏DIV.在我第二次单击按钮以隐藏DIV的那一刻,我的代码没有进入javascript函数的else侧(我已使用警报来显示消息).这是我的jscript函数:

Hi - I''m hoping someone can help me with this issue I''m having, I''ve created a DIV and set the display to "none" so on the Page Load everything in the DIV is hidden. But when I click a button I want to show the DIV and click the button again to Hide the DIV. At the minute when I click the button for the 2nd time to hide the DIV my code doesn''t step into the else side of the javascript function (i''ve used alerts to display messages). Here''s my jscript function:

function ShowEmailHistory() {
            function ShowEmailHistory() {
            if (document.getElementById("divEmailHistory").style.display = "none") 
            {
                document.getElementById("divEmailHistory").style.display = "block";
                alert("SHOW")
            }
            else 
            {
                document.getElementById("divEmailHistory").style.display = "none";
                alert("HIDE");
            }            
        }            
        }



和我的HTML:



and my HTML:

<ajaxToolkit:TabPanel ID="TabPanelEmail"  runat="server" HeaderText="Email">
    <ContentTemplate>
        <table width="100%">
            <tr valign="middle">
                <td align="right"><asp:Label ID="lblSendTo" runat="server" CssClass="Label_Small_Bold" Text="To:"></asp:Label></td>
                <td align="left"><asp:TextBox ID="txtSendTo" runat="server" CssClass="Input_Text_Long" Width="344px"></asp:TextBox></td>
            </tr>
            <tr valign="middle">
                <td align="right"><asp:Label ID="lblCc" runat="server" CssClass="Label_Small_Bold" Text="Cc:"></asp:Label></td>
                <td align="left"><asp:TextBox ID="txtCc" runat="server" CssClass="Input_Text_Long" Width="344px"></asp:TextBox></td>
            </tr>
            <tr valign="middle">
                <td align="right"><asp:Label ID="lblSubject" runat="server" CssClass="Label_Small_Bold" Text="Subject:"></asp:Label></td>
                <td align="left"><asp:TextBox ID="txtSubject" runat="server" CssClass="Input_Text_Long" Width="344px"></asp:TextBox></td>
            </tr>
            <tr valign="middle">
                <td align="right"><asp:Label ID="lblAttachment" runat="server" CssClass="Label_Small_Bold" Text="Attachment:"></asp:Label></td>
                <td align="left"><asp:FileUpload ID="fileUploadAttachment" runat="server" CssClass="Input_Text_Long" Width="344px" /></td>
            </tr>
            <tr valign="top">
                <td align="right"><asp:Label ID="lblMessage" runat="server" CssClass="Label_Small_Bold" Text="Message:"></asp:Label></td>
                <td align="left"><asp:TextBox id="txtBody" runat="server" CssClass="Input_Text_Long" TextMode="MultiLine" Rows="7" Width="560px"></asp:TextBox></td>
            </tr>
            <tr valign="top">
                <td align="right"> </td>
                <td align="right"><asp:Label ID="lblEmailError" runat="server" CssClass="Label_Small_Bold" Text=""></asp:Label> 
                                  <asp:Button ID="btnSendEmail" runat="server" CssClass="Button_XSmall" Text="Send Email" OnClick="btnSendEmail_Click" />
                </td>
            </tr>
            <tr valign="middle">
                <td align="left" colspan="2"><asp:Label ID="lblEmailAttachmentSaveError" Visible="False" runat="server" CssClass="Label_Red_Bold" Text="Cannot save file"></asp:Label></td>
            </tr>
            <tr valign="middle">
                <td align="center" colspan="2"><input type="button" id="btnShowEmailHistory" value="Show Email history"  önclick="javascript:ShowEmailHistory()" ></input></td>
            </tr>
            <tr valign="middle">
                <td colspan="2" align="center" style="display:none">
                    <div id="divEmailHistory">
                        <table width="100%">
                            <tr valign="middle">
                                <td align="left" colspan="2">
                                    <asp:GridView id="gvEmailHistory" runat="server" ForeColor="#333333" DataKeyNames="AuthNumber,ToRecipient,Filename" BorderColor="Black" HorizontalAlign="Left" PageSize="5"
                                        GridLines="Horizontal" Width="100%" Font-Size="X-Small" Font-Names="Verdana" CellPadding="4" EmptyDataText="No Files Found" AutoGenerateColumns="False">
                                        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Small" VerticalAlign="Top" HorizontalAlign="Left"  />
                                        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" HorizontalAlign="Left"  />
                                        <EditRowStyle BackColor="#FFFF80"  />
                                        <SelectedRowStyle Font-Bold="False"  />
                                        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Left"  />
                                        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" HorizontalAlign="Left"  />
                                        <AlternatingRowStyle BackColor="White" ForeColor="#284775"  />
                                        <PagerSettings Mode="NumericFirstLast"  />
                                        <EmptyDataRowStyle CssClass="Label_Small_Bold" ForeColor="#C00000" HorizontalAlign="Center"  />
                                        <Columns>
                                            <asp:BoundField DataField="AuthNumber" HeaderText="Auth Number" ReadOnly="True" Visible="False">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="EmailDate" HeaderText="Date" ReadOnly="True" Visible="True">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="CcRecipient" HeaderText="Cc" ReadOnly="True" Visible="False">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="Subject" HeaderText="Subject" ReadOnly="True" Visible="True">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="Body" HeaderText="Message" ReadOnly="True" Visible="True">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:TemplateField HeaderText="File Name">
                                                <ItemTemplate>
                                                    <asp:HyperLink ID="lnkFilename" Target="_blank" NavigateUrl='<%# @ConfigurationManager.AppSettings["Email_Attachment_location"] + Eval("AuthNumber","") + @"\" + Eval("Filename","")%>' runat="server"><%# Eval("Filename","")%></asp:HyperLink>
                                                </ItemTemplate>
                                                <HeaderStyle HorizontalAlign="Left" />
                                                <ControlStyle CssClass="Label_Small" />
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="Filesize" HeaderText="Size (kb)"  Visible="False">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                            <asp:BoundField DataField="Filetype" HeaderText="Type" Visible="False">
                                                <HeaderStyle HorizontalAlign="Left" />
                                            </asp:BoundField>
                                        </Columns>
                                    </asp:GridView>
                                </td>
                            </tr>
                        </table>
                    </div>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</ajaxToolkit:TabPanel>

推荐答案

在用于IE的firefox/IEWebDevloperTool上安装firebug并调试脚本.
Install firebug on firefox/IEWebDevloperTool for IE and debug the script.


javascript if()是问题(=而不是==)应该是

如果(document.getElementById("divEmailHistory").style.display =="none")
the javascript if() was the problem (= instead of ==) it should have been

if (document.getElementById("divEmailHistory").style.display == "none")


这篇关于隐藏DIV的javascript函数无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆