如何使Dropdown箭头(插入图标引导程序)更改为单击?

时间:2016-09-28 18:48:45

标签: javascript jquery html twitter-bootstrap drop-down-menu

如何在bootstrap nav-pills中的下拉列表中更改插入符号图标?

我不知道如何使用hide.bs.dropdown

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <style>
     .caret-container {
      float: right;
    }
    .caret.caret-up {
      border-top-width: 0;
      border-bottom: 4px solid;
    }
  </style>
</head>
<body>
  <ul class="nav nav-pills nav-stacked" id="stacked-menu">
    <a href="" class="list-group-item">Quality</a>
    <a href="zertifikate.html" class="list-group-item active">Cert</a>
    <ul class="nav nav-pills nav-stacked collapse in" id="p1">
      <li data-toggle="collapse" data-parent="#p1" href="#pv1">
        <a class="nav-container list-group-item">Leist<div class="caret-container"><span class="caret caret-up"></span></div></a>
      </li>
      <ul class="nav nav-pills nav-stacked collapse out" id="pv1">
        <li><a href="" class="list-group-item">sub1111</a></li>
        <li><a href="" class="list-group-item">sub2222</a></li>
      </ul>
    </ul>
    <a href="" class="list-group-item">Fdsafdsfs</a>
  </ul>
  <script>
    $(document).ready(function(){
      $(".pv1").on("hide.bs.dropdown", function(){
      $(".pv1").html('<span class="caret"></span>');
  });
      $(".collapse").on("show.bs.dropdown", function(){
        $(".btn").html('<span class="caret caret-up"></span>');
      });
    });
  </script>


  
  <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</body>
</html>

2 个答案:

答案 0 :(得分:1)

在Glyphicons和font-awesome发表后真正说道。没有人使用插入符号。所以你看起来像这样CaretLiveFiddle ....或者你可以尝试Ghypicons与导航丸崩溃GlyphiconsUseForCollapse。如果您有任何疑问,可以在评论中提问我。谢谢。

<!DOCTYPE html>
<html>
<head>
  <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="https://code.jquery.com/jquery-3.1.0.min.js"></script>
 <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <style>
     .caret-container {
      float: right;
    }
   .caret-up{
        border-top-width: 0;
      border-bottom: 4px solid;
   }
  </style>
</head>
<body>
  <ul class="nav nav-pills nav-stacked" id="stacked-menu">
   

 <a href="" class="list-group-item">Quality</a>
    <a href="zertifikate.html" class="list-group-item active">Cert</a>
    <ul class="nav nav-pills nav-stacked collapse in" id="p1">
      <li data-toggle="collapse" data-parent="#p1" href="#pv1">
        <a class="nav-container list-group-item">Leist<div class="caret-container"><span class="caret caret-down"></span></div></a>
      </li>
      <ul class="nav nav-pills nav-stacked collapse out" id="pv1">
        <li><a href="" class="list-group-item">sub1111</a></li>
        <li><a href="" class="list-group-item">sub2222</a></li>
      </ul>
    </ul>
    <a href="" class="list-group-item">Fdsafdsfs</a>
  </ul>
  <script>
  $('.collapse').on('shown.bs.collapse', function() {
  $(this).parent().find(".caret-down").removeClass("caret-down").addClass("caret-up");
}).on('hidden.bs.collapse', function() {
  $(this).parent().find(".caret-up").removeClass("caret-up").addClass("caret-down");
});

  </script>

</body>
</html>

答案 1 :(得分:0)

$(document).ready(function(){
  $(".pv1").on("hide.bs.dropdown", function(){
  $(".pv1").html('<span class="caret"></span>');
});
  $(".collapse").on("show.bs.dropdown", function(){
    $(".btn").html('<span class="caret caret-up"></span>');
  });
});

您的javascript正在引用pv1类。你应该把它改成

$(document).ready(function(){
  $("#pv1").on("hide.bs.dropdown", function(){
  $("#pv1").html('<span class="caret caret-down"></span>');
});
  $(".collapse").on("show.bs.dropdown", function(){
    $(".btn").html('<span class="caret caret-up"></span>');
  });
});

以便使用pv1 id。

访问您的元素

另外,正如@mhodges指出的那样,向&#34;隐藏&#34;添加一个插入符号,以便它变为向下。否则,当它恢复时,它将变为向上插入符号,并且永远不会恢复为向下。