您的位置:首页 > Web前端 > BootStrap

bootstrap-select核心options

2018-03-04 17:56 489 查看
译文来自:http://silviomoreto.github.io/bootstrap-select/options/

Options可以通过数据属性传递也可以通过Javascript传递。对于数据属性,在option前加上data-,就像data-style=”” or data-selected-text-format=”count”一样。

1.通过Javascript设置属性

$('.selectpicker').selectpicker({
'width':300,
'actionsBox':true,
'countSelectedText':'已选中{0}个,共{1}个可供选择',
'selectedTextFormat':"count>2",
'selectAllText':'全选',
'deselectAllText':'取消全选',
'dropdownAlignRight':'auto',
'header':'页眉',
'liveSearch':true,
'liveSearchNormalize':true,
'liveSearchPlaceholder':'12',
'liveSearchStyle':'contains',
'noneSelectedText':'一个都没有选择...',
'showIcon':false
});


2.属性表格

4000
NameTypeDefaultDescription
actionsBoxbooleanfalse当设置为true时,将会添加两个按钮到下拉选项的 最上面,Select All & Deselect All)。要和多选配合使用才起作用
containerstring | falsefalse
countSelectedTextstring | functionfunction设置显示文本的格式,当设置selectedTextFormat为‘count’或‘count>#’,{0} 是选中的数量,{1} 是可供选择的总数。当被设置为一个函数,第一个参数是被选中的数量,第二个是可供选择的总数,函数必须返回一个字符串。
selectedTextFormat‘values’ | ‘static’ | ‘count’ | ‘count > x’ (where x is an integer)‘values’指定如何使用多选显示选择,’values’显示选中的列表,被multipleSeparator分割符分割,’static’只显示title的占位符,’count’显示选中选项的个数,’count > x’显示跟’values’一样直到选中的个数大于x,它显示的又跟’count’一样
deselectAllTextstring‘Deselect All’在actionsBox启用的使用,清除所有的选项按钮上的文本
dropdownAlignRightboolean | ‘auto’false将菜单对齐到右边而不是左边,如果设置为’auto’,菜单将会自动对齐到右边,如果没有足够的空间显示将会靠左对齐
dropupAutobooleantrue检查哪里有更多的空间,上面或者下面,如果上面有足够的空间就向上正常打开,但有更多的空间,dropup就正常打开,否则它变成dropup,如果dropupAuto设为false,dropups必须手动设置。
headerstringfalse在菜单顶部添加一个页眉;默认情况下包括一个关闭按钮
hideDisabledbooleanfalse删除禁用的选项和选项组,从菜单属性为data-hide-disabled: true的属性。
iconBasestring‘glyphicon’设置基础使用不同的图标字体代替Glyphicons,如果更换基础图标,你也可能会去更改tickIcon,如果新的图标字体使用不同的命名方案。
liveSearchbooleanfalse当设置为true时,添加一个搜索框的下拉列表到顶部
liveSearchNormalizebooleanfalse设置liveSearchNormalize为true,允许不敏感的搜索。
liveSearchPlaceholderstringnull当设置为一个字符串,一个占位符属性等于选项字符串将被添加到智能搜索输入。
liveSearchStylestring‘contains’当设置为’contains’时,搜索将显示包括搜索文本的选项,例如搜索pl,将会返回Apple、Plum和Plantain,将设置为startsWith,搜索的话只会返回Plum和Plantain。
maxOptionsinteger | falsefalse多选下拉框当设置为一个整数,选择的最大数量不能超过这个整数。这个选项也可以存在以data-attribute形式对于多选数组,在这种情况 下它只适用于。
maxOptionsTextstring | array | functionfunction文本只有在maxOptions设置启用的时候才起作用,选择给定场景的最大选项数。如果使用一个函数,它一定要返回一个数组,array[0] is the text used when maxOptions is applied to the entire select element. array[1] is the text used when maxOptions is used on an optgroup. If a string is used, the same text is used for both the element and the optgroup.
mobilebooleanfalse当设置为true,使设备的本机菜单用于选择菜单.
multipleSeparatorstring‘, ‘设置选项选中的分割符
noneSelectedTextstring‘Nothing selected’当多个选择没有选定选项时显示的文本.
selectAllTextstring‘Select All’当’actionsBox’启用时全选按钮显示的字符串
selectedTextFormat‘values’ | ‘static’ | ‘count’ | ‘count > x’ (x是一个整数)‘values’Specifies how the selection is displayed with a multiple select.’values’ displays a list of the selected options (separated by multipleSeparator. ‘static’ simply displays the select element’s title. ‘count’ displays the total number of selected options. ‘count > x’ behaves like ‘values’ until the number of selected options is greater than x; after that, it behaves like ‘count’.
selectOnTabbooleanfalsetreats the tab character like the enter or space characters within the selectpicker dropdown.
showContentbooleantrueWhen set to true, display custom HTML associated with selected option(s) in the button. When set to false, the option value will be displayed instead.
showIconbooleanfalseWhen set to true, display icon(s) associated with selected option(s) in the button.
showSubtextbooleanfalseWhen set to true, display subtext associated with a selected option in the button.
showTickbooleanfalseShow checkmark on selected option (for items without multiple attribute).
size‘auto’ | integer | false‘auto’When set to ‘auto’, the menu always opens up to show as many items as the window will allow without being cut off.When set to an integer, the menu will show the given number of items, even if the dropdown is cut off.When set to false, the menu will always show all items.
stylestring | nullnullWhen set to a string, add the value to the button’s style.
tickIconstring‘glyphicon-ok’Set which icon to use to display as the “tick” next to selected options.
titlestring | nullnullThe default title for the selectpicker.
width‘auto’ | ‘fit’ | css-width | false (where css-width is a CSS width with units, e.g. 100px)falseWhen set to auto, the width of the selectpicker is automatically adjusted to accommodate the widest option.When set to a css-width, the width of the selectpicker is forced inline to the given value.When set to false, all width information is removed.
windowPaddinginteger | array0This is useful in cases where the window has areas that the dropdown menu should not cover - for instance a fixed header. When set to an integer, the same padding will be added to all sides. Alternatively, an array of integers can be used in the format [top, right, bottom, left]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: