简体   繁体   English

如何使用span标签和glyphicon而不是bootstrap上的按钮制作下拉菜单?

[英]How to make a dropdown menu with span tag and glyphicon instead of button on bootstrap?

I was looking for that a long time without success. 我一直在寻找很长时间没有成功。

I found a link that explain how to do it, but it has no example and I don't know how to implement on my website. 我找到了一个说明如何执行此操作的链接 ,但没有示例,我也不知道如何在我的网站上实施。

Anyone can help me? 有人可以帮助我吗? Anyone knows how to do it? 有人知道该怎么做吗?

Here's the code that you're looking for, that with jquery: 这是您要查找的,带有jquery的代码:

$('#willtoggle').on('click', function (event) {
    $("#toggled").toggle();
});

the #willtoggle is a span with the class of caret defined on bootstrap, so on click, it'll toggle the dropdown-menu(that have the id="toggled"). #willtoggle是一个在引导程序上定义了插入符号类的跨度,因此在单击时,它将切换下拉菜单(具有id =“ toggled”)。

And this code for hiding it when clicking outside: 并在外部单击时隐藏该代码:

$(document).on('click', function(event) {
  if ($(event.target).closest('.dropdown').length === 0) {
      $("#toggled").hide();
  }
});

Here's the JSFiddle that I made. 这是我制作的JSFiddle

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

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