1

我遇到了一些问题,试图找出一种在单击 ul li 列表中的帖子中的特定内容时附加动态菜单切换的方法。但是,由于某种原因,它不能很好地工作。

我在想 Each(); 和最近();+ 查找();在 jQuery 中。

这是我想要实现的图片:

在此处输入图像描述

欢迎任何帮助!谢谢,希望解决方案可以是动态的。

代码:

  var activeClass = 'openToggler', showingDropdown, showingMenu, showingParent;
        /* hides the current menu */
        var hideMenu = function () {
            if (showingDropdown) {
                showingDropdown.removeClass(activeClass);
                showingMenu.hide();
            }
        };

        /* recurse through dropdown menus */
        $('.micro-post').each(function () {
            /* track elements: menu, parent */
            var dropdown = $(this);
            //var opts = dropdown.closest("opts");

            //console.log(opts);

            var menu = dropdown.next('.dropdown-menu'), parent = dropdown.parent();
            /* function that shows THIS menu */
            var showMenu = function () {
                hideMenu();
                showingDropdown = $(this).closest('.micro-post').addClass(activeClass);
                showingMenu = menu.show();
                showingParent = parent;
            };
            /* function to show menu when clicked */
            dropdown.bind('click', function (e) {
                if (e) e.stopPropagation();
                if (e) e.preventDefault();
                showMenu();
            });
            /* function to show menu when someone tabs to the box */
            dropdown.bind('focus', function () {
                showMenu();
            });
        });

        /* hide when clicked outside */
        $(document.body, ".micro-post").bind('click', function (e) {
            if (showingParent) {
                var parentElement = showingParent[0];
                if (!$.contains(parentElement, e.target) || !parentElement == e.target) {
                    hideMenu();
                }
            }
        });
4

1 回答 1

0

好吧,感谢您的帮助,但是在重新编写所有内容之后,我想出了一种解决方法,并且我自己的解决方案现在可以完美运行。非常感谢您尝试帮助我,但我已经完成了。如果我遇到任何问题,我会在这里发帖,StackOverFlow Rocks!:)

于 2013-08-25T10:38:58.000 回答