Jquery PreventDefault 与 drupal 菜单

发布于 2024-11-23 15:36:01 字数 2528 浏览 1 评论 0原文

我在 drupal 中有页脚菜单,其中包含很多菜单项。

<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 函数。

$('#footer li.expanded a:first-child').click(function(e) {
        e.preventDefault;
    });

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

I have footer menu in drupal which contains so many menu items.

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

This is just the first li of the menu. What I want is, when I click on Business menu nothing will happen. So for this I used Jquery preventDefault function.

$('#footer li.expanded a:first-child').click(function(e) {
        e.preventDefault;
    });

But when I execute the script it just stops working of every links under the expanded menu.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叹倦 2024-11-30 15:36:01

这应该可以做到:

$('#footer li.expanded a').click(function(e) {
    if(!$(this).parent().hasClass('leaf')){
        e.preventDefault();
    }
});

This should do it:

$('#footer li.expanded a').click(function(e) {
    if(!$(this).parent().hasClass('leaf')){
        e.preventDefault();
    }
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文