Foo.ClassName ='classname'无效

时间:2015-01-26 19:53:27

标签: javascript html css asp.net

前六行的类名行没有。

function ShowShippingInfo() {
    var QuoteInfo = document.getElementById("QuoteInfo");
    var ShippingInfo = document.getElementById("ShippingInfo");
    var Comments = document.getElementById("Comments");

    QuoteInfo.style.display = "none";
    ShippingInfo.style.display = "block";
    Comments.style.display = "none";

    QuoteInfo.className = 'tab';
    ShippingInfo.className = 'tab active';
    Comments.className = 'tab';
};

这是我的HTML

<div onclick="ShowQuoteInfo();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Quote Info</strong></div>

<div onclick="ShowShippingInfo();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Shipping Info</strong></div>  

<div onclick="ShowComments();" style="border-left: thin solid #808080; border-right: thin solid #808080; border-top: thin solid #666666; border-bottom: thin none #999999; cursor: pointer; width: 100px; vertical-align: bottom; font-weight: normal; text-align: left;" class="tab"><strong class="auto-style198">Comments</strong></div>

我遇到的问题不是更改类名,我知道类选项卡和选项卡活动有效,因为它可以在我设置它时起作用 设置backgroundcolor也不起作用。

我正在使用谷歌浏览器

请帮助
感谢

PS:这是它正在展示和隐藏的潜水

 <div id="QuoteInfo">
                                            <table class="table_1">
                                                <tr>
                                                    <td style="vertical-align: top;" class="auto-style169" rowspan="2"><strong>Customer:</strong></td>
                                                    <td class="auto-style165" rowspan="2" style="vertical-align: top">
                                                        <asp:DropDownList ID="TCustomer" runat="server" Style="font-weight: bold;" AppendDataBoundItems="True" DataTextField="Name" DataValueField="Name" Height="27px" Width="171px">
                                                            <asp:ListItem></asp:ListItem>
                                                        </asp:DropDownList>
                                                        <br />
                                                        <asp:Label ID="LAddress" runat="server" Text="_"></asp:Label>
                                                    </td>
                                                    <td class="auto-style197"><strong>Quote</strong> <strong>No:</strong></td>
                                                    <td class="auto-style197">
                                                        <asp:TextBox ID="TQuoteNumber" runat="server" Width="182px" Enabled="False"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style196"><strong>Date:</strong></td>
                                                    <td class="auto-style196">
                                                        <asp:TextBox ID="TDate" runat="server" Width="182px" Enabled="False"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style194"><strong>Contact Person:</strong></td>
                                                    <td class="auto-style195">

                                                        <asp:TextBox ID="TContactPersonss" list="Contact" runat="server" Width="182px"></asp:TextBox>
                                                    </td>
                                                    <td class="auto-style195"><strong>Sales</strong> <strong>Person:</strong></td>
                                                    <td class="auto-style195">
                                                        <asp:TextBox ID="TSalesPerson" runat="server" Width="182px" Enabled="False"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style169"><strong>Status:</strong></td>
                                                    <td class="auto-style165">
                                                        <asp:DropDownList ID="TStatus" runat="server" Style="font-weight: bold;" AppendDataBoundItems="True" DataSourceID="SqlDataSource2" DataTextField="ItemName" DataValueField="ItemName" Height="27px" Width="171px">
                                                            <asp:ListItem></asp:ListItem>
                                                        </asp:DropDownList>
                                                        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:DRPConnectionString %>" SelectCommand="SELECT [ListName], [ItemName] FROM [Status] WHERE ([ListName] = @ListName)">
                                                            <SelectParameters>
                                                                <asp:Parameter DefaultValue="QuoteStatus" Name="ListName" Type="String" />
                                                            </SelectParameters>
                                                        </asp:SqlDataSource>


                                                    </td>
                                                    <td class="auto-style165"><strong>Expires</strong> <strong>in</strong> <strong>(Days):</strong></td>
                                                    <td class="auto-style165">
                                                        <asp:TextBox ID="TExpiresIn" runat="server" Width="182px" TextMode="Number"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style179"><strong>Estimated Lead Time:</strong></td>
                                                    <td class="auto-style180">
                                                        <asp:DropDownList ID="TEstimatedLeadTimes" runat="server" Height="26px" Width="223px">
                                                            <asp:ListItem Selected="True">None</asp:ListItem>
                                                            <asp:ListItem>1 to 2 weeks</asp:ListItem>
                                                            <asp:ListItem>2 to 3 weeks</asp:ListItem>
                                                            <asp:ListItem>3 to 4 weeks</asp:ListItem>
                                                            <asp:ListItem>4 to 5 weeks</asp:ListItem>
                                                            <asp:ListItem>5 to 6 weeks</asp:ListItem>
                                                            <asp:ListItem>6 to 7 weeks</asp:ListItem>
                                                            <asp:ListItem>7 to 8 weeks</asp:ListItem>
                                                            <asp:ListItem>8 to 9 weeks</asp:ListItem>
                                                        </asp:DropDownList>


                                                    </td>
                                                    <td class="auto-style180"><strong>PO Number:</strong></td>
                                                    <td class="auto-style180">
                                                        <asp:TextBox ID="TPurchaseOrder" runat="server" Width="182px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>




                                        <div id="ShippingInfo" style="display: none;">
                                            <table class="table_1">
                                                <tr>
                                                    <td style="vertical-align: top;" class="auto-style189">Name:</td>
                                                    <td class="auto-style165" style="vertical-align: top">

                                                        <asp:TextBox ID="TextBox16" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
                                                        <br />
                                                    </td>
                                                    <td class="auto-style192">Same as Customer:</td>
                                                    <td class="auto-style157">
                                                        <asp:CheckBox ID="CheckBox3" runat="server" Checked="True" Text=" " />
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style189">Address:</td>
                                                    <td class="auto-style165">

                                                        <asp:TextBox ID="TextBox4" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
                                                    </td>
                                                    <td class="auto-style191">City:</td>
                                                    <td class="auto-style165">
                                                        <asp:TextBox ID="TextBox5" runat="server" Width="182px" Enabled="False"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style188">State:</td>
                                                    <td class="auto-style171">

                                                        <asp:TextBox ID="TextBox15" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>


                                                    </td>
                                                    <td class="auto-style190">ZipCode:</td>
                                                    <td class="auto-style171">
                                                        <asp:TextBox ID="TextBox6" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td class="auto-style179"><strong>Email Address:</strong></td>
                                                    <td class="auto-style180">

                                                        <asp:TextBox ID="TextBox17" list="Contact" runat="server" Width="182px" AutoPostBack="True"></asp:TextBox>


                                                    </td>
                                                    <td class="auto-style180">&nbsp;</td>
                                                    <td class="auto-style180">&nbsp;</td>
                                                </tr>

                                            </table>
                                        </div>

                                        <div id="Comments" style="display: none;">
                                            <table class="table_1">
                                                <tr>
                                                    <td style="vertical-align: top;" class="auto-style169"><strong>Comment
                                                        <br />
                                                        For
                                                        <br />
                                                        Customer:</strong></td>
                                                    <td class="auto-style165" style="vertical-align: top">
                                                        <asp:TextBox ID="TComments" runat="server" Height="143px" TextMode="MultiLine" Width="697px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="vertical-align: top;" class="auto-style169"><strong>Comment

                                                        For<br />
                                                        Sales Person<br />
                                                        (Not visible on Quote)</strong></td>
                                                    <td class="auto-style165">

                                                        <asp:TextBox ID="TextBox19" runat="server" Height="143px" TextMode="MultiLine" Width="697px"></asp:TextBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </div>

1 个答案:

答案 0 :(得分:0)

您的HTML不包含任何ID。所以当你通过id引用时:

var QuoteInfo = document.getElementById("QuoteInfo");
var ShippingInfo = document.getElementById("ShippingInfo");
var Comments = document.getElementById("Comments");

你需要你的html标签也有这个id。