我有 3 个滑块范围:
<div class="container">
<div class="row" id="time" >
<div class="col-xs-4">
Days: <b>1</b> <input id="days" type="text" class="span2" value="" data-slider-min="1" data-slider-max="31" data-slider-step="1" data-slider-value="[0,31]"/> <b>31</b>
</div>
<div class="col-xs-4">
Months: <b>January</b> <input id="months" type="text" data-provide="slider" data-slider-step="1" data-slider-min="0" data-slider-max="12" data-slider-tooltip="show" data-slider-value="[0,12]" /> <b>December</b>
</div>
<div class="col-xs-4">
Years: <b>0</b> <input id="years" type="text" class="span2" value="" data-slider-min="0" data-slider-max="2017" data-slider-step="1" data-slider-value="[0,2017]"/> <b>Today</b>
</div>
</div>
</div>
我正在运行以下js:
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
getData = function() {
var data = {};
var temp = $('#days').slider().val().split(',');
data.days = temp[0];
temp = $('#months').slider().val().split(',');
data.months = months[temp[0]];
temp = $('#years').slider().val().split(',');
data.years = temp[0];
console.log(data);
}
$("#days, #years").slider({
tooltip: 'always',
});
$('#months').slider({
formatter: function(value) {
return months[value[0]] + " : " + months[value[1] - 1];
}
});
$("input").on("slide", function(slideEvt) {
getData();
});
基本上,当我们移动 a 时slider
,控制台输出当前value
的电流value
,输出为:
{days: "12", months: "July", years: "1396"}
这很好,但是如果我移动第二个滑块是因为我想做一个范围,那么第二个值不会显示,而它应该是:
{days: "12", days: "24", months: "July", months: "September", years: "1396", years: "1842"}
但是每个值或两者都应该只在我们实际移动每个值时出现slider
这是一个jsFiddle,检查控制台
注意,我实际上需要这种格式的值,因为它们将被视为某些元素的类:
例子
day22
february
year1632