简体   繁体   English

如何在html的导航栏中单击元素时打开链接

[英]how to open a link on click of an element in navbar in html

I'm trying to add the link to the first element of the dropdown that is "MORE" so that I could go to another page but I'm not able to do that. 我正在尝试将链接添加到下拉列表的第一个元素“ MORE”,以便可以转到另一个页面,但我无法做到这一点。 I have tried it many times but not able to do it. 我已经尝试了很多次,但无法做到。

The Code: 编码:

<li class="dropdown"><a href="#" class="dropdown-toggle" data-toggle="dropdown" style="font-family: 'Roboto', sans-serif; font-size: 15px; color: white;">More<b class="caret"></b></a>
  <ul class="dropdown-menu">
    <li><a href="#">Python</a></li>
    <li><a href="#">AngularJS Framework</a></li>
    <li><a href="#">.NET Framework Development</a></li>
    <li><a href="#">Swift App Development</a>   </li>
    <li class="divider"></li>
    <li><a href="Blogs/Java/Java-Page.aspx">Java App Development</a></li>
  </ul>
</li>

If you need the submenu to display onclick, consider using jQuery. 如果您需要子菜单来显示onclick,请考虑使用jQuery。 Or if you want the menu to appear on hover, remove the jQuery in this fiddle and uncomment the piece of CSS that will handle that. 或者,如果您希望菜单显示在悬停上,请删除此小提琴中的jQuery,然后取消注释将处理该问题的CSS。 - https://jsfiddle.net/awwys0z6/1/ . -https://jsfiddle.net/awwys0z6/1/ Otherwise, you may have to restructure your menu like this - Show hide divs on click in HTML and CSS without jQuery 否则,您可能必须像这样重新构建菜单- 在没有jQuery的情况下,单击HTML和CSS即可显示隐藏的div

$('.dropdown').click(function() {
    $('.show').toggle('.show');
});

Using jQuery 使用jQuery

$('element').on('click', function(){
//do whatever u want
});

Using javascript 使用JavaScript

<nav>
<div onclick="linkFn()">click here</div>
</nav>

function linkFn() {
//do whatever u want
}

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

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