单击后,Bootstrap Dropdowns不显示菜单

时间:2016-07-09 16:20:17

标签: javascript html twitter-bootstrap dropdown

这些是代码片段。下拉菜单不起作用。尝试了其他方法,但无法成功。我想只从这些代码中解决问题。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<div class="row">
    <div class="col-lg-12">      
    <div class="button-group">
    <button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown">Choose an item:
    <span class="caret"></span></button>
    <ul class="dropdown-menu">
      <li><a href="#" class="small" data-value="option1" tabindex="-1"><input type="checkbox" />Chicken Steam Momo</a></li>
      <li><a href="#" class="small" data-value="option2" tabindex="-1"><input type="checkbox" />Chicken Fried Momo</a></li>
      <li><a href="#" class="small" data-value="option2" tabindex="-1"><input type="checkbox" />Chicken Kothey Momo</a></li>
    </ul>
  </div>
  </div>
  </div>
productFlavors {
    Prod {
        applicationId 'com.test.app'
    }
    Qa{
        applicationId 'com.test.app.qa'
        versionName '1.2-QA'
    }
    Dev{
        applicationId 'com.test.app.dev'
        versionName '1.2-DEV'
    }
}

2 个答案:

答案 0 :(得分:1)

您错过了Bootstrap.js ...

var options = [];

$( '.dropdown-menu a' ).on( 'click', function( event ) {

   var $target = $( event.currentTarget ),
       val = $target.attr( 'data-value' ),
       $inp = $target.find( 'input' ),
       idx;

   if ( ( idx = options.indexOf( val ) ) > -1 ) {
      options.splice( idx, 1 );
      setTimeout( function() { $inp.prop( 'checked', false ) }, 0);
   } else {
      options.push( val );
      setTimeout( function() { $inp.prop( 'checked', true ) }, 0);
   }

   $( event.target ).blur();
      
   console.log( options );
   return false;
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<div class="row">
    <div class="col-lg-12">      
    <div class="button-group">
    <button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle="dropdown">Choose an item:
    <span class="caret"></span></button>
    <ul class="dropdown-menu">
      <li><a href="#" class="small" data-value="option1" tabindex="-1"><input type="checkbox" />Chicken Steam Momo</a></li>
      <li><a href="#" class="small" data-value="option2" tabindex="-1"><input type="checkbox" />Chicken Fried Momo</a></li>
      <li><a href="#" class="small" data-value="option2" tabindex="-1"><input type="checkbox" />Chicken Kothey Momo</a></li>
    </ul>
  </div>
  </div>
  </div>

答案 1 :(得分:0)

根据错误,您似乎还没有将jQuery导入到您的html中。