duanchai0028 2012-09-18 15:44
浏览 54

如何从动态创建的嵌套无序列表构建下拉菜单?

I have an unordered list that is dynamically generated in a loop with nested unordered lists. I would like to show just the <h4> nested list name </h4> and then, when clicked, the sub-list will display.

Here is the entire block of code that creates the lists:

    <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>

And here are two jQuery scripts that I tried but was unsuccessful in getting either to work:

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

and:

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

I am open to any suggestions.

  • 写回答

1条回答 默认 最新

  • donglang7236 2012-09-18 16:29
    关注

    Try this: It will show the .facet-option when the menu li is clicked.

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

    If you need to hide the other menus on click

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测