noUiSlider 多范围访问第一个句柄

noUiSlider multirange accessing first handle

我正在尝试构建一个具有多个句柄的 noUiSlider,我可以在其中获取表单提交的各个句柄之间的值。我可以访问所有句柄的值,但不能访问第一个句柄。试图在 console.log 上获取它的 id 没有给我任何帮助。如何访问第一个句柄? 我的例子在这里: Codepen Example

var multirange = document.getElementById("my-slider");
//initialize the slider
noUiSlider.create(multirange, {
  start: [1, 3, 6, 7],
  connect: [true, true, true, true, true],
  tooltips: [true, true, true, true],
  behaviour: "tap-drag",
  step: 0.25,
  range: {
    min: [0],
    max: [8]
  }
});

multirange.noUiSlider.on("update", function(values, handle) {
  var value = values[handle];

  if (handle) {
    //for debugging check the id of the current handle
    console.log(handle);
    //get the id of the corresponding input field
    var inputid = "input-number" + handle;
    //first handle value does not need to be processed further
    if (handle !== 0) {
      //get previous handle id field
      var prvid = handle - 1;
      //get previous handle value
      var prvvalue = values[prvid];
      //difference between current and previous value
      var diffvalue = value - prvvalue;
      var inputNumber = document.getElementById(inputid);
      inputNumber.value = diffvalue;
    } else {
      //first handle value should directly be written into the input field
      inputNumber.value = value;
    }
  }
});

谢谢Alon,

那是我的错误。 将 if 更改为

if (handle  !== undefined  ) {

现在也可以捕获 ID 为 0 的句柄