为Bootstrap框架(Bootstrap 4和5)提供了一个简单而可定制的输入微调器插件(缩小到4KB以下),使用户可以使用+/-按钮增加/减少数字。
# NPM $ npm install bootstrap-input-spinner --save
1.在html文档中加载必要的jQuery库和Bootstrap框架。
<link rel="stylesheet" href="/path/to/cdn/bootstrap.min.css" /> <script src="/path/to/cdn/jquery.slim.min.js"></script> <script src="/path/to/cdn/bootstrap.min.js"></script>
2.加载JavaScript文件输入-指针.js在jQuery之后。
<script src="bootstrap-input-spinner.js"></script>
3.为输入微调器创建一个普通数字输入。该插件支持本地输入属性,例如价值,最小值,最大值和步.
<input type="number" value="5" min="0" max="100" step="1">
4.通过调用数字输入上的函数来初始化输入微调器。
$("input[type='number']").inputSpinner();
5.如果要限制小数位数并禁用千位分隔符:
<input type="number" value="5" min="0" max="100" step="1"
data-decimals="2"
data-digit-grouping="false">
6.为输入元素添加前缀和后缀
<input type="number" value="5" min="0" max="100" step="1"
data-prefix=""
data-suffix="">
7.设置输入模式。默认值:“decimal”。
<input type="number" value="5" min="0" max="100" step="1"
inputmode="decimal">
8.可用于自定义输入微调器的插件选项。
$("input[type='number']").inputSpinner({
// button text/icons
decrementButton: "<strong>-</strong>",
incrementButton: "<strong>+</strong>",
// class of input group
groupClass: "input-group-spinner",
// button class
buttonsClass: "btn-outline-secondary",
// button width
buttonsWidth: "2.5em",
// text alignment
textAlign: "center",
// delay in milliseconds
autoDelay: 500,
// interval in milliseconds
autoInterval: 100,
// set this `true` to disable the possibility to enter or paste the number via keyboard
buttonsOnly: false,
// set this to `false` to disallow the use of the up and down arrow keys to step
keyboardStepping: true,
// the locale, per default detected automatically from the browser
locale: navigator.language,
// the editor (parsing and rendering of the input)
editor: I18nEditor,
// the template of the input
template: // the template of the input
'<div class="input-group ${groupClass}">' +
'<div class="input-group-prepend"><button style="min-width: ${buttonsWidth}" class="btn btn-decrement ${buttonsClass} btn-minus" type="button">${decrementButton}</button></div>' +
'<input type="text" inputmode="decimal" style="text-align: ${textAlign}" class="form-control form-control-text-input"/>' +
'<div class="input-group-append"><button style="min-width: ${buttonsWidth}" class="btn btn-increment ${buttonsClass} btn-plus" type="button">${incrementButton}</button></div>' +
'</div>'
});
9.事件处理程序:
changedElement.addEventListener("change", function(event) {
valueOutput.innerHTML = changedElement.value
})
10.以编程方式更改值:
instance.setValue(new value)
11.销毁实例。
instance.destroy()
版本3.2.0(2023-03-09)
版本3.1.14(2022-11-24)
版本3.1.13(2022-08-06)
版本3.1.12(2022-06-11)
第3.1.8版(2022-01-21)
v3.1.7 (2021-10-04)
v3.1.2 (2021-10-02)
v3.0.3 (2021-09-14)
v3.0.2 (2021-05-28)
v2.1.1 (2021-05-14)
2.0.12版(2021-04-29)
2.0.11版(2021-04-26)
2.0.10版(2021-03-30)
v1.17.2 (2021-01-28)
v1.17.0 (2021-01-19)
v1.16.9 (2021-01-11)
v1.16.8 (2020-10-26)
v1.16.5 (2020-09-25)
v1.16.4 (2020-09-17)
v1.15.4 (2020-09-14)
v1.14.2 (2020-09-14)
v1.14.1 (2020-09-08)
v1.13.20 (2020-08-27)
v1.13.17 (2020-08-02)
v1.13.16 (2020-07-28)
v1.13.11 (2020-07-21)
v1.13.10 (2020-07-20)
v1.13.6 (2020-06-06)
v1.13.4 (2020-04-02)
v1.13.3 (2019-12-18)
v1.12.7 (2019-10-31)
Â