我想要做的是將<span class="hideSelect">
元素的「我的下拉列表」文本替換爲單擊<li>
的文本,以使其工作像<select>
元素。使DIV和UL的行爲像一個SELECT元素
CSS:
.myDrop {
border: 1px solid #ddd;
border-radius: 3px;
padding: 5px 10px;
max- width: 100%;
min-width: 100%;
vertical-align: middle;
}
.mydrop ul {
display: none;
background: #fff;
border: 1px solid #ddd;
border-radius: 3px;
max-height: 250px;
overflow: auto;
}
.mydrop ul li {
padding: 5px 10px;
}
.mydrop ul li:hover {
background: #ddd;
}
的JavaScript:
$(".mydrop").click(function(e) {
e.stopPropagation();
$(".mydrop>ul").stop().slideToggle(500);
$(document).click(function(){
$(".mydrop>ul").hide();
});
});
$(".mydrop>ul li").click(function() {
$(".hideSelect").hide();
});
HTML:
<div class="container">
<div class="row">
<div class="col-md-3">
<div class="mydrop">
<div class="myDrop">
<span class="hideSelect">
<span id="caption">my dropdown</span>
<span class="pull-right"><i class="fa fa-caret-down"></i>
</span>
</span>
</div>
<ul id="options">
<li class="visilkl">Hot Dog, Fries and a Soda</li>
<li>Burger, Shake and a Smile</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
<li>Sugar, Spice and all things nice</li>
</ul>
</div>
</div>
</div>
</div>
什麼需要隱藏的部分代碼???與id mydrop或myDrop的div? –
希望你使用選擇框,對嗎?當我們點擊時,我想做同樣的事情,就像在選擇框上發生的一樣,可見的東西隱藏並且點擊的東西在選擇框上可見。 – Samar