jQuery 范围滑块事件触发

发布于 2024-09-28 16:34:11 字数 122 浏览 2 评论 0原文

使用 jQuery Range Slider 插件时出现问题。我想在每次滑块更改时触发一个事件。

我不知道哪个元素可以触发事件。例如,我想要一条警报消息,看看它是否有效。

谢谢

彼得

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

残花月 2024-10-05 16:34:11

要在用户停止移动旋钮后获取滑块值,请使用 change,否则使用 input 在旋钮移动时接收更新。

// 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);
}

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);
}
望笑 2024-10-05 16:34:11

您可以使用 4 个可能的事件。查看文档中的事件==> http://jqueryui.com/demos/slider/

您可以使用

  1. 开始
  2. 幻灯片
  3. 更改
  4. 停止

事件。

如果您想在每次更改滑块时执行一个功能,请尝试 change

假设您的幻灯片是 id 为 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/
       }
    });

});

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/
       }
    });

});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文