我在 jquery 上有自定义下拉列表,我的打开列表单击工作正常,但我需要通过单击正文来处理折叠单击按钮。
如何处理正文单击事件以折叠我的列表?
html
<div class="xn-dropdown">
<span class="select-button xn-select" >
<span>select
</span>
</span>
<div class="select-menu-wrap">
<div class="select-menu-modal">
<div class="select-menu-list">
<div class="select-menu-item">
<a href="#">itemnumber 1</a>
</div>
<div class="select-menu-item">
<a href="#">itemnumber 1</a>
</div>
<div class="select-menu-item">
<a href="#">itemnumber 1</a>
</div>
</div>
</div>
</div>
javascript
$(document).on("click",".select-button",function() {
$(this).toggleClass('select-button').addClass('selected');
$('.select-menu-wrap').show();
});
if(!$(".xn-select").hasClass('select-button')){
$(document).on("click","body",function() {
$('.xn-select').toggleClass('selected').addClass('select-button');
$('.select-menu-wrap').hide();
});
}
和小提琴(现在工作正常!)