简体   繁体   English

响应菜单问题-如何在移动环境中处理HREF和onclick事件

[英]Responsive menu issue - how to handle HREF and onclick event on mobile environment

I have a response menu called Flexy Menu which is excellent. 我有一个称为Flexy Menu的响应菜单,非常好。 But the issue I have is that when the menu loads on mobile (and no mouse present) I have a conflict where a href exists on the parent link but also this has an onClick event to open up the child menu. 但是我遇到的问题是,当菜单在移动设备上加载(并且没有鼠标)时,我在父链接上存在href时遇到了冲突,但是这也有一个onClick事件来打开子菜单。 See below as an example, the link "experience-sweden" also opens a dropdown for "touring-sweden" but just as the menu opens the href redirects it to another page 参见下面的示例,链接“ experience-sweden”也打开了“ touring-sweden”的下拉菜单,但正如菜单打开的href一样,它会将其重定向到另一个页面

<ul class="flexy-menu">
  <li><a  href="index" >Home</a><li>
  <li><a  href="experience-sweden" >Experience Sweden</a>
     <ul>
         <li><a href="touring-sweden">Touring Holidays</a>
     </ul>
  </li> 

I guess the solution is to somehow ignore the first click, so essentially have the href as # and then update once clicked to the actual href. 我猜解决方案是以某种方式忽略第一次单击,因此基本上将href设置为#,然后单击一次即可更新为实际的href。 However to make it difficult the menu is entirely dynamic and pulled from a database so the javascript would have to have to have some PHP breakins I am guessing. 但是,要使菜单变得更加动态是困难的,并且菜单是完全动态的,并且是从数据库中拉出的,因此javascript必须不得不具有一些我猜想的PHP breakins。 Any advice appreciated. 任何建议表示赞赏。

i would suggest that you dont apply the onClick event on the anchor tag but apply it on a span tag. 我建议您不要在锚标签上应用onClick事件,而应在span标签上应用。

so 所以

  1. place a span tag inside the "parent" anchor 将span标签放置在“父”锚内
  2. apply onClick event on the span tag 在span标签上应用onClick事件
  3. style the span tag as an arrow using css 使用css将span标签设置为箭头样式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM