如何在滑块操作事件之前获取滑块的值

How To Get Value of Slider Before Slider Manipulation Event?

本文关键字:获取 操作 事件      更新时间:2023-09-26

我需要在滑块操作开始之前获取滑块的值。

如果用户使用 Jquerymobile 滑块输入框单击,则使用焦点事件有效。 但是,如果用户操作滑块,则它不起作用。

幻灯片启动事件不起作用。 在幻灯片启动事件之前,它总是有点偏离滑块值??

有没有办法调用滑块输入的最后一个值? 或者在操作滑块值之前捕获它?

这是我到目前为止尝试过的...

(在此示例中,我想侦听类 entry_percent 中滑块的任何更改。

var entry_percent_class = $('.entry_percent');
var previous_value;
var change;

$( ".entry_percent" ).on( 'slidestart', function( event ) {
    previous_value = $(this).val();
    alert(previous_value);
});
entry_percent_class.on('tap', function() { // if the user inputs a number in the slider box, capture the number before it's changed.
    previous_value = $(this).val();
    alert(previous_value);
});

entry_percent_class.on('focus', function() { // if the user inputs a number in the slider box, capture the number before it's changed.
    previous_value = $(this).val();
    //alert(previous_value);
});
entry_percent_class.on('change', function() { // if the user inputs a number in the slider box, capture the number before it's changed.
        previous_value = $(this).val();
        //alert(previous_value);
    });

使用 stop 事件保存值并在需要时拯救它。比使用变量更好,使用 data

$( ".entry_percent" ).on( 'slidestart', function( event ) {
    previous_value = $(this).data("oldvalue");
    alert(previous_value);
});
$( ".entry_percent" ).on( 'slidestop', function( event ) {
    $(this).data("oldvalue",$(this).val());
});

小提琴