jQuery range slider event trigger

∥☆過路亽.° 提交于 2019-12-08 05:38:21

问题


there`s a problem using the jQuery Range Slider plugin. I want to trigger an event every time the slider changed.

I don`t know on which elemt i can trigger events. For exmaple i wana have an alert message ro see if it works.

Thanks

Peter


回答1:


There are 4 possible events you can use. Look under events in the docs ==> http://jqueryui.com/demos/slider/

You can use the

  1. start
  2. slide
  3. change
  4. stop

events.

If you want to do a function everytime the slider is changed try change.

Let's say your slide is an element with id of slider:

$(function() {    // <== doc ready

    $( "#slider" ).slider({
       change: function(event, ui) {
           // Do your stuff in here.

           // You can trigger an event on anything you want:
           $(selector).trigger(theEvent);

           // Or you can do whatever else/
       }
    });

});



回答2:


To get the slider value once the user has stopped moving the knob use change otherwise use input to receive updates as the knob is moved.

// Logs the value when the user has released the slider
$('.my-slider').on('change', valueUpdated);

// Logs the value while the user is moving the slider
$('.my-slider').on('input', valueUpdated);

function valueUpdated (e) {
    var val = $(e.element).val();
    console.log(val);
}


来源:https://stackoverflow.com/questions/3983155/jquery-range-slider-event-trigger

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!