UP step (increment) and output events...">

How to listen for step up event for input type = "number"

I want to listen to the <input type="number" />UP step (increment) and output events using jQuery. (currently I can only understand how to listen to the change event)

enter image description here

+3
source share
3 answers

There are no recent events for upand down. You can use eventchange

$(".counter").change(function () {
   alert($(this).val());      
})

Demo

You can try something like: you can save the previous value and compare with the current value and identify up or down

$(".counter").change(function () {
    if ($(this).data('old-value') < $(this).val()) {
        alert('Alert up');
    } else {
        alert('Alert dowm');
    }
    $(this).data('old-value', $(this).val());
})

Demo

+2
source

up down. - change. oninput, , :

$('#myinput').on('input', function() {

});
0

You must do this:

var $counter = $("your_counter");
var number = $counter.val();

$counter.change(function () {
   if($counter.val() > number)
       alert('up');
   else
       alert('down');
   number = $counter.val();
});

Here is a demo: http://jsfiddle.net/6bb8S/

0
source

All Articles