문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top