使用 Bootstrap-slider 插件在工具提示中格式化数字
Formatting Number within Tooltip using the Bootstrap-slider plugin
在使用 bootstrap-slider 插件时,我似乎想不出一种方法来更改工具提示中的数字。
.slider .tooltip.top {
margin-top: -45px !important;
margin-left: 2px;
}
.slider .tooltip-inner {
white-space: nowrap;
border-radius: 0px;
}
.slider .tooltip.top .tooltip-arrow {
border-top-color: #198294 !important;
}
<div class="container">
<div class="row">
<div class="col-md-6" style="margin-top: 75px;">
<div class="slider-wrapper slider-primary slider-strips slider-ghost">
<input class="input-range" type="text" data-slider-step="1" data-slider-value="14, 75" data-slider-min="0" data-slider-max="100" data-slider-range="true" data-slider-tooltip_split="true" data-slider-tooltip="hide" />
</div>
</div>
</div>
</div>
工具提示中的1000,应该是1000
tooltip中的1000023,应该是1,000,023
您可以使用 toLocaleString() and formatter callback:
$(':text').slider({
formatter: function(value) {
return 'Current value: ' + value.toLocaleString('en-US', { style: 'decimal', useGrouping: true });
}
});
.slider .tooltip.top {
margin-top: -45px !important;
margin-left: 2px;
}
.slider .tooltip-inner {
white-space: nowrap;
background-color: white;
color: #747679;
font-family: TT Norms;
border: 1px solid #198294;
border-radius: 0px;
}
.slider .tooltip.top .tooltip-arrow {
border-top-color: #198294 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.6.2/css/bootstrap-slider.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.6.2/bootstrap-slider.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6" style="margin-top: 75px;">
<div class="slider-wrapper slider-primary slider-strips slider-ghost">
<input class="input-range" type="text" data-slider-step="1" data-slider-value="3023" data-slider-min="0"
data-slider-max="1000023" data-slider-range="true" data-slider-tooltip-split="true" data-slider-tooltip="show" />
</div>
</div>
</div>
</div>
在使用 bootstrap-slider 插件时,我似乎想不出一种方法来更改工具提示中的数字。
.slider .tooltip.top {
margin-top: -45px !important;
margin-left: 2px;
}
.slider .tooltip-inner {
white-space: nowrap;
border-radius: 0px;
}
.slider .tooltip.top .tooltip-arrow {
border-top-color: #198294 !important;
}
<div class="container">
<div class="row">
<div class="col-md-6" style="margin-top: 75px;">
<div class="slider-wrapper slider-primary slider-strips slider-ghost">
<input class="input-range" type="text" data-slider-step="1" data-slider-value="14, 75" data-slider-min="0" data-slider-max="100" data-slider-range="true" data-slider-tooltip_split="true" data-slider-tooltip="hide" />
</div>
</div>
</div>
</div>
工具提示中的1000,应该是1000 tooltip中的1000023,应该是1,000,023
您可以使用 toLocaleString() and formatter callback:
$(':text').slider({
formatter: function(value) {
return 'Current value: ' + value.toLocaleString('en-US', { style: 'decimal', useGrouping: true });
}
});
.slider .tooltip.top {
margin-top: -45px !important;
margin-left: 2px;
}
.slider .tooltip-inner {
white-space: nowrap;
background-color: white;
color: #747679;
font-family: TT Norms;
border: 1px solid #198294;
border-radius: 0px;
}
.slider .tooltip.top .tooltip-arrow {
border-top-color: #198294 !important;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap-theme.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.6.2/css/bootstrap-slider.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-slider/10.6.2/bootstrap-slider.min.js"></script>
<div class="container">
<div class="row">
<div class="col-md-6" style="margin-top: 75px;">
<div class="slider-wrapper slider-primary slider-strips slider-ghost">
<input class="input-range" type="text" data-slider-step="1" data-slider-value="3023" data-slider-min="0"
data-slider-max="1000023" data-slider-range="true" data-slider-tooltip-split="true" data-slider-tooltip="show" />
</div>
</div>
</div>
</div>