日期:2014-05-17  浏览次数:20482 次

有关下拉树菜单JS样式
HTML code

<body>
    <form id="form1" runat="server">
    <asp:Repeater ID="Repeater1" runat="server">
        <ItemTemplate>
            <div id="main1" onclick="document.getElementById('child1').style.display=(document.getElementById('child1').style.display =='none')?'':'none'">
                <%#Eval("btype") %>
                <asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("bid") %>' />
            </div>
            <div id="child1" style="display: none">
                <ul>
                    <asp:Repeater ID="Repeater2" runat="server">
                        <ItemTemplate>
                            <li><a href="#">
                                <%#Eval("type") %></a></li>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>
            </div>
        </ItemTemplate>
    </asp:Repeater>
    </form>
</body>



现在的问题是不管点repeater循环出来的哪个<%#Eval("btype") %>都只显示第一个<%#Eval("btype") %>的子节点DIV。。

请问如何设置onclick事件点哪个<%#Eval("btype") %> 就显示相应的 子节点的DIV.


------解决方案--------------------
<script type="text/javascript">
function expand(obj) {
var id = obj.parentElement.id;
//alert(id);
var divs = document.getElementById(id).getElementsByTagName('div');
for (var i = 0; i < divs.length; i++) {
if (divs[i].id == "child1") {
divs[i].style.display = (divs[i].style.display == 'none') ? '' : 'none';
break;
}
}
}
</script>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div id="diva" runat="server"> <div id="main1" onclick="expand(this);">
type
</div>
<div id="child1" style="display: none;">
<ul>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<li><a href="#">type</a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
------解决方案--------------------
<body>
<form id="form1" runat="server">
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div id="main1" onclick="document.getElementById('child<%#Eval("bid") %>').style.display=(document.getElementById('child1').style.display =='none')?'':'none'">
<%#Eval("btype") %>
<asp:HiddenField ID="HiddenField1" runat="server" Value='<%#Eval("bid") %>' />
</div>
<div id="child<%#Eval("bid") %>" style="display: none&qu