jQuery移动滑块输入更改事件

时间:2021-02-18 20:13:00

I'm working with the jQuery mobile slider input. I can have multiple sliders in my page, and what happen it's that the "change" event it's fired very often, not just when the actual input value changes. This is my code:

我正在使用jQuery移动滑块输入。我的页面中可以有多个滑块,发生的事情是“更改”事件经常被触发,而不仅仅是实际输入值发生变化时。这是我的代码:

<div class="questionContent ui-hide-label" data-role="fieldcontain">
    <input type="range" class="slider" value="" min="1" max="5" data-highlight="true" name="slider"  data-theme="b" />  
</div>

$('input.slider').each(function() {
    $(this)
    .bind('change',function() {
        console.log('changed')
    })
})

I also created a jsFiddle for that: http://jsfiddle.net/EAewE/

我还为此创建了一个jsFiddle:http://jsfiddle.net/EAewE/

1 个解决方案

#1


4  

The issue is that jQuery in the background is changing the value of the input tied to the slider whenever the mouse is clicked, moved slightly etc. so the 'change' is actually triggering that often because it should be.

问题是,只要点击鼠标,轻微移动等等,后台的jQuery就会改变绑定到滑块的输入值,因此“更改”实际上是因为它应该触发。

In jQuery Mobile you are better off using the slidestop event which will only trigger when the slider stops moving. Note that this event is not fired when the input's value is changed programmatically, only when the actual slider is engaged by the user.

在jQuery Mobile中,您最好使用slidestop事件,该事件仅在滑块停止移动时触发。请注意,仅当用户使用实际滑块时,才会以编程方式更改输入值时不会触发此事件。

#1


4  

The issue is that jQuery in the background is changing the value of the input tied to the slider whenever the mouse is clicked, moved slightly etc. so the 'change' is actually triggering that often because it should be.

问题是,只要点击鼠标,轻微移动等等,后台的jQuery就会改变绑定到滑块的输入值,因此“更改”实际上是因为它应该触发。

In jQuery Mobile you are better off using the slidestop event which will only trigger when the slider stops moving. Note that this event is not fired when the input's value is changed programmatically, only when the actual slider is engaged by the user.

在jQuery Mobile中,您最好使用slidestop事件,该事件仅在滑块停止移动时触发。请注意,仅当用户使用实际滑块时,才会以编程方式更改输入值时不会触发此事件。