Jquery Plus/Minus Incrementer

后端 未结 10 1194
挽巷
挽巷 2021-01-01 03:53

I want to have a client side Plus / Minus system where a user can click the plus and a value is incremented by 1, minus and the value is decreased by 1, the value should nev

10条回答
  •  一整个雨季
    2021-01-01 04:13

    The jquery part

    // initialize counter
    var counter = 0;
    
    // set the + functionality
    $('#plus').click( function(){$('#display').html( ++counter )} );
    // set the - functionality
    $('#minus').click( function(){$('#display').html( (counter-1<0)?counter:--counter )} );
    // initialize display
    $('#display').html( counter );
    

    and the html part

    +
    -
    

提交回复
热议问题