在 github 上,它说搜索框现在在所选选择框中是可选的。有谁知道如何删除它?
问问题
22443 次
3 回答
49
当前版本的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>
于 2012-10-03T01:42:41.990 回答
3
只需在需要时隐藏它
$('.chzn-search').hide();
于 2012-09-03T15:59:57.643 回答
0
display:none
selected.jquery.js 只是用类在 div中设置搜索框的样式chzn-search
<div class="chzn-search"><input type="text" autocomplete="off" style="display:none;" /></div>
于 2012-08-30T05:30:23.197 回答