嗨我試圖將ul > li
轉換爲select > option
,如果我選擇dropdown
列表中的第一個選項,應該查看它。我完成了它,但是當我在單個頁面中使用它兩次時出現錯誤。多個下拉值引導
$(".dropdown-menu").on('click', 'li a', function(){
$(".btn:first-child").text($(this).text());
$(".btn:first-child").val($(this).text());
});
*{
border-radius: 0 !important;
}
li{
list-style: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<li role="presentation" class="dropdown">
<label>Quantity
<a href="#" class="dropdown-toggle btn btn-default" id="drop5" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Select
<span class="caret"></span>
</a>
<ul class="dropdown-menu" id="menu2" aria-labelledby="drop5">
<li><a href="#">In Stock</a></li>
<li><a href="#">Out of Stock</a></li>
</ul>
</label>
</li>
<hr>
<li role="presentation" class="dropdown">
<label>Quantity
<a href="#" class="dropdown-toggle btn btn-default" id="drop5" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">
Select
<span class="caret"></span>
</a>
<ul class="dropdown-menu" id="menu2" aria-labelledby="drop5">
<li><a href="#">Price</a></li>
<li><a href="#">Dollar</a></li>
</ul>
</label>
</li>
你得到哪個錯誤? – bhansa
我已更新代碼,請檢查它:) –