gianlucagiacometti / bootstrap-select
Bootstrap select 元素的扩展
Requires
- twbs/bootstrap: ^5.2
- twbs/bootstrap-icons: ^1.9
This package is auto-updated.
Last update: 2024-09-18 17:29:27 UTC
README
Bootstrap (https://bootstrap.ac.cn) Select 元素的扩展类
此程序使用纯JavaScript编写,适用于Bootstrap 5.2.x和现代浏览器。
ECMAScript的最小版本为2017。我保留在任何时候不另行通知切换到ECMAScript新版本的权力。
尽管W3C建议没有在HTML 5中提及它,但HTML 4.01建议(《https://www.w3.org/TR/html401/interact/forms.html#h-17.6》)中指出:“注意。建议实现者,HTML的未来版本可能会扩展分组机制以允许嵌套组(即,OPTGROUP元素可以嵌套)。这将允许作者表示更丰富的选择层次。”因此,bsSelect类已经是递归的。
bsSelect类使用Bootstrap的Input和Dropdown元素,以实现最大程度的兼容性。
此程序采用MIT许可证发布。
需求
Bootstrap >= 5.2.2
Boostrap Icons >= 1.9(仅用于搜索和选项图像)
注意:版本号将遵循Bootstrap版本号(例如,1.5.2.2.1 - Bootstrap发布版本加粗)
用法
在html <head>部分中添加以下行
<link rel="stylesheet" href="bootstrap.select.css">
<script src="bootstrap.select.js"></script>
注意:“href”和“src”属性的值必须复制两个文件所在的文件夹结构。
"selectInserted" CSS动画提供了一种创建新的bsSelect类元素的自动方式。
您可以选择以下操作:
-
将“bootstrap-select”类添加到<select>元素中。
<select id="myselect" class="bootstrap-select">...</select>
-
在DOM已加载时通过JavaScript动态添加“bootstrap-select”类。
<select id="myselect">...</select> document.querySelector("#myselect").classList.add("bootstrap-select")
-
通过JavaScript手动创建新的类元素,不使用“bootstrap-select”类(randomIndex的值必须是一个16位字符串)。
<select id="myselect">...</select> let randomIndex = "" + Date.now() + Math.floor(Math.random()*1000) let mySelectElement = new bsSelect("myselect", randomIndex, classElementParameters) # The classElementParameters is an optional object. The default value is {}.
选项
类元素的可选参数
<select>元素的可选类
<select>元素的可选属性
<select>元素的可选属性
<option>元素的可选属性
<option>元素的可选属性
方法
进一步开发
- 更新ARIA角色和属性