在onchange结束时触发输入类型范围的事件

在onchange结束时触发输入类型范围的事件

问题描述:

如何触发事件或检测输入类型范围的onchange事件结束。

How to trigger an event or detect the end of onchange event for input type range.

$('.slider').on('change',function(e){
      console.log(e.target.value);
});

现在,当我开始拖动范围输入时,这将返回许多控制台日志。我想在onc​​hange事件结束时获取值。如何实现这个目标?

Now this will return a number of console logs when I start dragging the range input. I wanted to get the value at the end of onchange event. How to achieve this ?

谢谢;)

嘿您可以尝试使用Gururaj 去抖动 功能。它会延迟事件处理程序的触发,因此您可以根据需要在 onchange 事件的末尾获取输入值。 Lodash可以使用debounce 功能。

Hey Gururaj you can try debounce function. It delays the firing of your event handler so you can get your input value at the end of onchange event as you want it. Lodash has a implementation of the debounce function you can use.

$range.on('change', _.debounce(function() {
  $display.text($(this).val());
}, 250));

这里有点演示