当我在下拉列表中选择多个复选框时,下拉列表不应关闭

时间:2019-03-31 05:45:50

标签: javascript wordpress

您好,我在滑块https://www.villasalesbali.com/上具有位置和属性类型的搜索功能,它们具有选择下拉菜单和复选框。但是,当我尝试执行多个复选框时,下拉列表将关闭。我想要的是,当用户仍在复选框上进行多个复选框时,下拉列表仍处于打开状态。但是当用户单击另一个位置框区域时,下拉列表将关闭。

我尝试使用触发功能来显示和显示下拉菜单,但现在无法正常工作,因为用户应该能够在不关闭下拉菜单的情况下执行多个复选框

var expanded = false;

function showCheckboxes2() {
 var checkboxes = document.getElementById("checkboxes2");
 if (!expanded) {
  checkboxes.style.display = "block";
  expanded = true;
 } else {
  checkboxes.style.display = "none";
  expanded = false;
 }


$(document).ready(function(){
    // Show hide popover
    $("#locationtrigger").click(function(){
        $(this).find("#checkboxes2").slideToggle("fast");
    });
});
$(document).on("click", function(event){
    var $trigger = $("#locationtrigger");
    if($trigger !== event.target && !$trigger.has(event.target).length){
        $("#checkboxes2").slideUp("fast");
    }            
});


<div id="locationtrigger" class="selectBox" onclick="showCheckboxes2()">
 <select  id=select-property-type class=search-select>
<option>Select an option</option>
 </select>
<div class="overSelect"></div>
</div>

<div id="checkboxes2">
 <label for="one">
<input type="checkbox" name="location[]" value="balangan"/>Balangan</label>
 <label for="two">
    <input type="checkbox" name="location[]" value="berawa"/>Berawa</label> 
 </div>

我希望在下拉菜单中选中多个复选框后,下拉菜单仍会打开,但实际上不起作用。

0 个答案:

没有答案