日期:2014-05-16  浏览次数:20339 次

菜单中append添加的子节点,再为其append添加子节点就出问题了,求指点
要做一个动态加载的菜单。从.ashx里加载数据,默认前台页面里只有一级节点,点击加载下一级节点,加载到第三级就有问题了,点击加载完后再点击不能收回,什么原因呢
HTML code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="AppMenu_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="../Content/jquery-1.7.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(function() {
            $("#AppMenu div span").click(function() {
                // $(this).css("background", "red");
                var m_div = $(this);
                if (m_div.closest("div").children("div").text() == "") {
                    var mid = $(this).attr("id");
                    // alert(mid);
                    $.post("AppMenuExt.ashx?p=" + mid, function(data, status) {
                        if (status != "success") { alert("加载失败"); }
                        else {
                            //alert(data.toString());
                            // m_div.closest("div").children("div").css("background", "green");
                            if (data.toString() != null) {
                                m_div.closest("div").children("div").append(data.toString());
                                // m_div.closest("div").children("div").append("<span>aaaa</span>");
                                //alert(m_div.children("img").attr("src"));
                                m_div.children("img").attr("src", "./images/menu2.png");
                                new appMenu1("mid", mid);
                                //alert(mid);
                            }
                        }
                    });
                }
                else {
                    //alert("div not null");
                    if (m_div.closest("div").children("div").css("display") == "none") {
                        m_div.children("img").attr("src", "./images/menu2.png");
                        m_div.closest("div").children("div").css("display", "block");
                    }
                    else {
                        m_div.children("img").attr("src", "./images/menu1.png");
                        m_div.closest("div").children("div").css("display", "none");
                    }
                }
            });
        });
        function appMenu1(key, value) {
            $(".folder").click(function() {
                // alert("key=" + key + "|value=" + value);
                //$(this).css("background", "blue");
                var divspan = $(this);
                //alert(mid);
                if (divspan.closest("div").children().text() == "") {
                    var mid = $(this).attr("id");
                    $.post("AppMenuExt.ashx?p=" + mid, function(data, status) {
                        if (status != "success") { alert("加载失败"); }
                        else {
                            //  alert(data.toString());
                            if (data.toString().length !