首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有drupal菜单的Jquery preventDefault

带有drupal菜单的Jquery preventDefault
EN

Stack Overflow用户
提问于 2011-07-14 20:30:14
回答 1查看 477关注 0票数 0

我在drupal中有一个页脚菜单,里面包含了很多菜单项。

代码语言:javascript
复制
<ul class="menu">
<li class="expanded first business">
<a title="" href="/content/business-tab">Business</a>
<ul class="menu">
<li class="leaf first about_business_mobile">
<a title="" href="/content/about-business-mobile">About Business Mobile</a>
</li>
<li class="leaf business_mobile_solutions">
<a title="" href="/content/business-pay-monthly">Business Mobile Solutions</a>
</li>
<li class="leaf value_packs">
<a title="" href="/content/business-value-packs">Value Packs</a>
</li>
<li class="leaf mobile_broadband">
<a title="" href="/content/mobile-broadband">Mobile Broadband</a>
</li>
<li class="leaf handsets">
<a title="" href="/content/handsets">Handsets</a>
</li>
<li class="leaf overseas_roaming">
<a title="" href="/content/overseas-roaming">Overseas Roaming</a>
</li>
<li class="leaf last overseas_calling_rates">
<a title="" href="/content/overseas-calling-rates">Overseas Calling Rates</a>
</li>
</ul>
</li>
<li class="expanded personal">
<a title="" href="/content/personal">Personal</a>
<ul class="menu">
<li class="leaf first about_personal_mobile">
<a title="" href="/content/personal-prepay">About Personal Mobile</a>
</li>
<li class="leaf personal_mobile_solutions">
<a title="" href="/content/personal-prepay">Personal Mobile Solutions</a>
</li>
<li class="leaf value_packs">
<a title="" href="/content/additional-packs-0">Value Packs</a>
</li>
<li class="leaf mobile_broadband">
<a title="" href="/content/mobile-broadband">Mobile Broadband</a>
</li>
<li class="leaf handsets">
<a title="" href="/content/handsets">Handsets</a>
</li>
<li class="leaf overseas_roaming">
<a title="" href="/content/overseas-roaming">Overseas Roaming</a>
</li>
<li class="leaf last overseas_calling_rates">
<a title="" href="/content/overseas-calling-rates">Overseas Calling Rates</a>
</li>
</ul>
</li>
</ul>

这只是菜单上的第一道菜。我想要的是,当我点击商业菜单什么也不会发生。为此,我使用了Jquery preventDefault函数。

代码语言:javascript
复制
$('#footer li.expanded a:first-child').click(function(e) {
        e.preventDefault;
    });

但是当我执行脚本时,它只是停止了展开菜单下的每个链接的工作。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-07-14 20:46:59

这应该可以做到:

代码语言:javascript
复制
$('#footer li.expanded a').click(function(e) {
    if(!$(this).parent().hasClass('leaf')){
        e.preventDefault();
    }
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6693139

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档