【发布时间】:2018-08-02 03:51:27
【问题描述】:
我有一个带有 select2 插件的多选下拉菜单。当下拉菜单打开时,用户滚动窗口并单击未触发单击事件的某个位置。相反,窗口会自动滚动并专注于下拉菜单。
请在此处找到演示。在示例中向下滚动并打开选择框,保持选择框处于打开状态,向上滚动并点击内容 1
$(document).ready(function() {
$("#multiselectDropdown").select2()
$("h1").on("click", function() {
alert("clicked " + $(this).text())
})
});
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/css/select2.min.css"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.5/js/select2.min.js"></script>
<h1>
Content1
</h1>
<h1>
Content2
</h1>
<h1>
Content3
</h1>
<h1>
Content4
</h1>
<h1>
Content5
</h1>
<h1>
Content6
</h1>
<h1>
Content7
</h1>
<h1>
Content8
</h1>
<h1>
Content9
</h1>
<h1>
Content10
</h1>
<select id="multiselectDropdown" style="width:200px" multiple>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
</select>
【问题讨论】:
标签: javascript jquery html jquery-select2