【问题标题】:How do I build a dropdown menu from a dynamically created nested unordered list?如何从动态创建的嵌套无序列表构建下拉菜单?
【发布时间】:2012-09-18 15:44:22
【问题描述】:

我有一个无序列表,它是在带有嵌套无序列表的循环中动态生成的。我想只显示<h4> nested list name </h4>,然后单击时会显示子列表。

这是创建列表的整个代码块:

    <ul class="faceted-menu">
<?php
    // Loop through faceted menus
    while(shopp('collection.facet-menus')) :

    // Skip menus with no options
    if ( ! shopp('collection.facet-menu-has-options')) continue;
?>
<li>
    <h4 style="color: #303030;"><?php
    // current facet filter name
    shopp('collection.facet-name'); ?></h4>
    <ul class="facet-option" style="display:none;">
        <?php
        // Loop through filter options for this faceted menu
        while(shopp('collection.facet-options')) : ?>
            <li>
                <a href="<?php
                    // toggle url for current filter option
                    esc_url(shopp('collection.facet-option-link')); ?>"><?php
                    // the full label of the facet filter option
                    shopp('collection.facet-option-label'); ?></a>&nbsp;(<span class="count"><?php
                // the number of products sharing this facet
                shopp('collection.facet-option-count'); ?></span>)
            </li>
        <?php endwhile; ?>
    </ul>
</li>
<?php endwhile; ?>
    </ul>

以下是我尝试过的两个 jQuery 脚本,但都未能成功:

    $("ul.faceted-menu li").click(function(event) { 
$(this).find("ul.facet-option").removeAttr('style'); 
    });

和:

    $("ul.faceted-menu li").live('click', function() { 
$(this).find("ul.facet-option").removeAttr('style');  
    });

我愿意接受任何建议。

【问题讨论】:

    标签: php jquery drop-down-menu unordered


    【解决方案1】:

    试试这个:当点击菜单 li 时它会显示 .facet-option。

      $("ul.faceted-menu li").click(function() { 
         $(".facet-option", this).show();
      });
    

    如果您需要在点击时隐藏其他菜单

     $("ul.faceted-menu li").click(function() { 
         $(".facet-option").hide();
         $(".facet-option", this).show();
      });
    

    【讨论】:

    • 乍得,尝试了你的答案,但没有成功。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-01
    • 1970-01-01
    • 2011-08-25
    • 2014-11-14
    • 2023-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多