【问题标题】:Using the following tree navigation script, how to make the heading trigger the drop down?使用下面的树形导航脚本,如何让标题触发下拉?
【发布时间】:2023-03-18 12:34:01
【问题描述】:

我们使用以下脚本进行下拉导航:

http://www.onlinetools.org/tools/dom-tree-menu-puredom/#

但是,只有在单击 [+] 或 [-] 时才会触发下拉菜单。我们喜欢让标题本身触发下拉菜单。喜欢:

[+] Heading
[+] Heading 2
[+] Heading 3

当我们点击 [+] 以及“标题”这个词时,我们希望下拉列表看起来像这样:

[-] Heading
 -- Content 1
 -- Content 2
 -- Content 3
[+] Heading 2
[+] Heading 3

目前,只有 [+] 触发下拉菜单,“标题”仅允许我们放置普通链接。

【问题讨论】:

  • 到目前为止你有任何代码吗?
  • 还没有放到我们的网站上。我只是使用网站上完全相同的代码来测试它应该如何工作。所以基本上,代码就是上面链接中的代码。

标签: javascript tree navigation drop-down-menu


【解决方案1】:

linkParent:false改为linkParent:true

如果您将其更改为 true,我有一种感觉,标题也可以进行链接。

如果你看一下第 41 行,它会设置点击处理程序。第一个标签 [0] 是箭头,第二个标签 [1] 我相信是标题

pde.addEvent(parentLI.getElementsByTagName('a')[0],'click',pde.showhide,false);
parentLI.getElementsByTagName('a')[0].onclick=function(){return false;} // Safari hack
if(pde.linkParent){
    pde.addEvent(parentLI.getElementsByTagName('a')[1],'click',pde.showhide,false);
    parentLI.getElementsByTagName('a')[1].onclick=function(){return false;} // Safari hack

}

提示:他们在脚本的开头也有很好的评论。

// boolean to make the parent link collapse the section or not 

    linkParent:false,

【讨论】:

  • 谢谢!没注意到那张纸条。 :D
猜你喜欢
  • 1970-01-01
  • 2021-05-27
  • 1970-01-01
  • 2019-02-12
  • 2016-04-03
  • 1970-01-01
  • 1970-01-01
  • 2020-09-03
  • 2018-05-04
相关资源
最近更新 更多