gpt4 book ai didi

javascript - 如何从 Chosen JS 中删除搜索框?

转载 作者:行者123 更新时间:2023-12-01 18:34:18 25 4
gpt4 key购买 nike

在 github 上,它说搜索框现在在所选选择框中是可选的。有谁知道怎么删除吗?

最佳答案

Chosen的当前版本提供了两种方法来控制搜索框的显示。两者都在初始化期间作为选项传入。要完全隐藏搜索框,请传入选项 "disable_search": true:

$("#mySelect").chosen({
"disable_search": true
});

或者,如果您想在有一定数量的选项时显示搜索,请使用选项 "disable_search_threshold": numberOfOptions (其中 numberOfOptions 是最小数量显示搜索框之前所需的选项):

$("#mySelect").chosen({
"disable_search_threshold": 4
});

jQuery(function($) {
// Create a set of OPTION elements from some dummy data
var words = ["lorem", "ipsum", "dolor", "sit", "amet,", "consectetur", "adipiscing", "elit", "duis", "ullamcorper", "diam", "sed", "lorem", "mattis", "tristique", "integer", "pharetra", "sed", "tortor"],
options = $($.map(words, function(word) {
return $(document.createElement('option')).text(word)[0];
}));
$('select').each(function() {
// Add the dummy OPTIONs to the SELECT
var select = $(this).append(options.clone());
// Initialize Chosen, using the options from the
// `data-chosen-options` attribute
select.chosen(select.data('chosen-options'));
});
});
body {
font-family: sans-serif;
font-size: .8em; }
label {
display: block;
margin-bottom: 1.4em; }
label .label {
font-weight: bold;
margin-bottom: .2em; }
select {
width: 14em; }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chosen/1.5.1/chosen.jquery.min.js"></script>

<label>
<div class='label'>Default behavior</div>
<select name='default' data-chosen-options='{}'></select>
</label>
<label>
<div class='label'>No search at all</div>
<select name='no-search' data-chosen-options='{ "disable_search": true }'></select>
</label>
<label>
<div class='label'>Search iff more than 4 items</div>
<select name='conditional-search' data-chosen-options='{ "disable_search_threshold": 4 }'></select>
</label>
<label>
<div class='label'>Search iff more than 32 items</div>
<select name='conditional-search' data-chosen-options='{ "disable_search_threshold": 32 }'></select>
</label>

关于javascript - 如何从 Chosen JS 中删除搜索框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12161354/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com