如何在滑块操纵事件之前获得滑块的价值?

时间:2014-11-24 10:05:26

标签: javascript jquery jquery-mobile

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

如果用户使用Jquerymobile滑块输入框单击,则使用on focus事件。但是如果用户操纵滑块,它就不起作用。

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

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

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

(在这个例子中,我想听一下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);

    });

1 个答案:

答案 0 :(得分:1)

使用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());
});

FIDDLE

相关问题