2015-03-31 79 views

回答

3

喜歡this demo

JS:

$('#myDropdown > li > a').click(function(e){ 
    $('#myDropdown > li > a').removeClass('selected'); 
    $(this).addClass('selected'); 
}); 

CSS(以隱藏檢查,除非它是一個 '選擇' 元素內):

#myDropdown > li > a > .fa{ 
    visibility:hidden; 
} 
#myDropdown > li > a.selected > .fa{ 
    visibility:visible; 
} 

HTML:

<div class="input-group-btn"> 
    <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown" aria-expanded="false"> <span class="caret"></span> 
     <span class="sr-only">Toggle Dropdown</span> 
    </button> 
    <!-- added an ID for the javascript --> 
    <ul id="myDropdown" class="dropdown-menu" role="menu"> 
     <li> 
      <a href="#"> 
       <i class="fa fa-check"></i> 
       <span class="search-option">Option 1</span> 
      </a> 
     </li> 
     <li> 
      <a href="#"> 
        <i class="fa fa-check "></i> 
        <span class="search-option">Option 2</span> 
      </a> 
     </li> 
    </ul> 
</div> 
+0

美麗,完美的作品! – user2818430 2015-03-31 17:02:19

+1

:)很高興能夠提供幫助 – Ted 2015-03-31 17:05:31