Question

I have a simple numeric keypad with buttons which work as expected. You click a button and that number is displayed in the text area.

My question concerns adding 2 buttons to the keypad that will (+) increase or (-) decrease the number in the text area.

Please see the demo here, http://jsfiddle.net/froze1906/cHPvx/

What do I need to add to activate the + and - buttons?

Était-ce utile?

La solution

Try the following:

$('.dec').click(function(){
    var val = parseInt($('#number_field').val(), 10);
    if (val != 0) {
      $('#number_field').val(val - 1)
    }
})

$('.inc').click(function(){
    var val = parseInt($('#number_field').val(), 10);
    if (val != 4) {
      $('#number_field').val(val + 1)
    }
})   

DEMO

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top