0

嗨,我有一个 javascript,用于更改三个 div 的显示属性

下面是代码

function tabChanged(sender, args) {
    debugger;
    var tabIndex = sender.get_activeTabIndex();
    switch (tabIndex) {
        case 0:
            document.getElementById('divcarllist').style.display = 'block';
            document.getElementById('divcarpdlist').style.display = 'none';
            document.getElementById('divcarlxlist').style.display = 'none';
            break;
        case 1:
            document.getElementById('divcarpdlist').style.display = 'block';
            document.getElementById('divcarllist').style.display = 'none';
            document.getElementById('divcarlxlist').style.display = 'none';
            break;
        case 2:
            document.getElementById('divcarllist').style.display = 'none';
            document.getElementById('divcarpdlist').style.display = 'none';
            document.getElementById('divcarlxlist').style.display = 'block';
            break;
    }
}

和 div 设计是

<div style="height: 100%; display: block;">
    <div id="divcarllist" runat="server" class='flexcroll' style="height: 69px; width: 100%;
        float: right; display: block">
        <asp:DataList ID="dlcarllist" runat="server" Height="69px" RepeatDirection="Horizontal"
            SelectedIndex="0" Width="100%" Style="float: left">
            <ItemTemplate>
                <img alt='<%#String.Concat(Eval("carcapacity"),"|",Eval("carid"),"|", Eval("carRegno"))%>'
                    src='<%#Eval("carimage") %>'
                   </ItemTemplate>
        </asp:DataList>
    </div>

    <div id="divcarpdlist" runat="server" class='flexcroll' style="height: 69px; width: 100%;
        float: right; display: none">
        <asp:DataList ID="dlcarpdlist" runat="server" Height="69px" RepeatDirection="Horizontal"
            SelectedIndex="0" Width="100%" Style="float: left">
            <ItemTemplate>
                  <img alt='<%#String.Concat(Eval("carcapacity"),"|",Eval("carid"),"|", Eval("carRegno"))%>'
                    src='<%#Eval("carimage") %>'
            </ItemTemplate>
        </asp:DataList>
    </div>
    <div id="divcarlxlist" runat="server" class='flexcroll' style="height: 69px; width: 100%;
        float: right; display: none">
        <asp:DataList ID="dlcarlxlist" runat="server" Height="69px" RepeatDirection="Horizontal"
            SelectedIndex="0" Width="100%" Style="float: left" RepeatLayout="Flow">
            <ItemTemplate>
                 <img alt='<%#String.Concat(Eval("carcapacity"),"|",Eval("carid"),"|", Eval("carRegno"))%>'
                    src='<%#Eval("carimage") %>'
            </ItemTemplate>
        </asp:DataList>
    </div>
</div>

但这不起作用,因为第二个两个 div 不显示,但如果我将所有 div 的显示属性设置为阻止,那么这个 javascript 工作正常,我无法理解这个问题。所以请这里的任何人都可以帮助我。

4

0 回答 0