禁用下拉菜单的父链接(disabling parent link of a dropdown menu)

编程入门 行业动态 更新时间:2024-10-24 06:27:35
禁用下拉菜单的父链接(disabling parent link of a dropdown menu) <li class="menu-229 menuparent menu-path-front even"> <a title="About" href="/tca/">about</a> <ul style="display: none; visibility: hidden;"> </li>

以上是我的动态生成下拉菜单的设置示例。

ul是带链接的下拉菜单,但是我想禁用关于可点击的标签。 我不想让下拉的父母成为一个链接。

我试过了:

$('.menuparent').click(function(e) { e.preventDefault() // or return false; });

但此代码也会禁用下拉菜单链接。

对不起,忘了提到这个菜单是由Drupal生成的。 我认为我不能碰它。 我只能用我得到的东西来工作。

<li class="menu-229 menuparent menu-path-front even"> <a title="About" href="/tca/">about</a> <ul style="display: none; visibility: hidden;"> </li>

Above is an example of how my dynamaically generated dropdown menu is setup.

The ul is the dropdown menu with links, however I want to disable the About a tag from being clickable. I dont want parents of dropdown to be a link.

I tried:

$('.menuparent').click(function(e) { e.preventDefault() // or return false; });

but this code disables the dropdown menu links as well.

Sorry, forgot to mention this menu is generated by Drupal. I don't think I can touch it. I can only work with what I am given.

最满意答案

用prev()试试这个选择器:

$('.menuparent > ul').prev('a').click(function(e) { e.preventDefault(); });

Try this selector with prev():

$('.menuparent > ul').prev('a').click(function(e) { e.preventDefault(); });

更多推荐

本文发布于:2023-08-07 08:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463800.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜单   链接   disabling   parent   dropdown

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!