2

我正在使用 IonRangeSlider,其中有 3 个自定义值:

["Value1","Value2","Value3"] 

并且类型是single.

现在我想要的是,我想以某种方式检测 from 和 to 值如果我从Value1to切换,Value2那么我希望它们两个值都包含在 2 个不同的变量中,因为我有一些基于 from 和 to 值的计算。但我能做的只是可以获得 From 值,如Value1.

下面是我的代码。

$('#Strategy').ionRangeSlider({
      type: 'single',
      grid: true,
      values: ["Value1","Value2","Value3"],
      onFinish: function (obj) {                
          alert(obj.from_value);
      }
});
4

1 回答 1

1

工作小提琴

在这种single情况下,如果您查看回调的响应参数,to则始终是,但传递的数组的第一项也将始终是,因此您可以像这样得到两者:nullonFinishtofrom/to

var maintenanceStrategyItems = ["Preventive","Optimal","Corrective"];
var old_value=maintenanceStrategyItems[0];

$('#Strategy').ionRangeSlider({
  type: 'single',
  grid: true,
  values: maintenanceStrategyItems,
  onChange: function (data) {
    console.log(old_value, data.from_value);
    old_value=data.from_value;
  }
});

希望这可以帮助。

var maintenanceStrategyItems = ["Preventive","Optimal","Corrective"];
var old_value=maintenanceStrategyItems[0];

$('#Strategy').ionRangeSlider({
  type: 'single',
  grid: true,
  values: maintenanceStrategyItems,
  onChange: function (data) {
    console.log(old_value, data.from_value);
    old_value=data.from_value;
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
<link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.skinFlat.css" rel="stylesheet"/>
<link href="http://ionden.com/a/plugins/ion.rangeSlider/static/css/ion.rangeSlider.css" rel="stylesheet"/>
<script src="http://ionden.com/a/plugins/ion.rangeSlider/static/js/ion-rangeSlider/ion.rangeSlider.js"></script>
<input type="text" id="Strategy" value="" />

于 2016-12-17T10:05:29.550 回答