禁用下拉菜单的父链接(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(); });更多推荐
发布评论