如何通过点击按钮从ion.rangeSlider组件中获取低值和高值?
这是我的jQuery代码:
<script>
$(document).ready(function(){
$("#range_1").ionRangeSlider({
min: 10,
max: 50,
from: 10,
to: 20,
type: 'double',
step: 1,
prettify: true,
hasGrid: false
});
});
</script>
<script>
$(document).ready(function(){
$('#get_values').click(function(){
var low = $('#range_1').... ???;
var high = $('#range_1').... ???;
alert(low);
});
});
</script>
答案 0 :(得分:14)
// Launch plugin
$("#range").ionRangeSlider({
type: "double",
min: 0,
max: 1000,
from: 200,
to: 500
});
// Saving it's instance to var
var slider = $("#range").data("ionRangeSlider");
// Get values
var from = slider.result.from;
var to = slider.result.to;
请参阅http://jsfiddle.net/2qLum6s7/处的解决方案。适用于最新版本的Ion.RangeSlider(2.1.2)。
答案 1 :(得分:6)
这是一个解决方案:http://jsfiddle.net/IonDen/xaaw56bk/
var $range = $(".js-range-slider"),
$result = $(".js-result"),
$getvalues = $(".js-get-values"),
from = 0,
to = 0;
var saveResult = function (data) {
from = data.fromNumber;
to = data.toNumber;
};
var writeResult = function () {
var result = "from: " + from + ", to: " + to;
$result.html(result);
};
$range.ionRangeSlider({
type: "double",
min: 10,
max: 50,
from: from,
to: to,
onLoad: function (data) {
saveResult(data);
writeResult();
},
onChange: saveResult,
onFinish: saveResult
});
$getvalues.on("click", writeResult);
答案 2 :(得分:6)
之前的回答是基于旧的插件API,不再适用。这是2.x版本的新版本: http://jsfiddle.net/IonDen/2L15xoym/
var $range = $(".js-range-slider"),
$result = $(".js-result"),
$getvalues = $(".js-get-values"),
from = 0,
to = 0;
var saveResult = function (data) {
from = data.from;
to = data.to;
};
var writeResult = function () {
var result = "from: " + from + ", to: " + to;
$result.html(result);
};
$range.ionRangeSlider({
type: "double",
min: 10,
max: 50,
from: from,
to: to,
onStart: function (data) {
saveResult(data);
writeResult();
},
onChange: saveResult,
onFinish: saveResult
});
$getvalues.on("click", writeResult);
答案 3 :(得分:4)
使用jQuery的data()方法:
var low = $('#range_1').data().from;
var high = $('#range_1').data().to;
答案 4 :(得分:1)
const range = $('#range_1');
const rangeData = range.data('ionRangeSlider');
const start = rangeData.result.from;
const max = rangeData.result.max;
// rangeData.result['property']
版本2.3.0(已测试)
答案 5 :(得分:0)
var val = $('#theSpecificSliderID').slider('value'); // Get value <br>
$('#theSpecificSliderID').slider('value', 33); // Set value
答案 6 :(得分:0)
使用开始,更改或完成过载。我正在使用完成重载并将值更新为SomeValue元素。
$("#Range_1").ionRangeSlider({
min: 0,
max: 100,
type: 'single',
step: 1,
postfix: " %",
prettify: false,
hasGrid: true,
onFinish: function(data){
var value = data.fromNumber;
$("#SomeValue").val(value);
}
});
答案 7 :(得分:0)
此方法适用于最新版本。使用事件 onChange 从属性“from”和“to”获取数据。 Ion.RangeSlider v2.3.1:
var slider = $('.js-range-slider');
slider.ionRangeSlider({
type: "double",
prefix: '$',
grid: true,
});
slider.on("change", function () {
var $inp = $(this);
var from = $inp.data("from"); // get data from attribute
var to = $inp.data("to"); // get data from attribute
console.log(from, to);
});
HTML 标记:
<input type="text" class="js-range-slider" name="my_range" value="" data-min="100" data-max="4000" data-from="1000" data-to="2000"/>