How to increase the value of a quantity field with jQuery?

前端 未结 8 1164
北荒
北荒 2021-01-07 05:25

I have a form with some quantity field and a plus and minus sign on each side,

    
product1
8条回答
  •  太阳男子
    2021-01-07 05:43

    Thanks so much for everyone who got involved. All I drew upon and was able to come up with this in the end, that served the site very well (it was just the css that was a pain!)

    HTML:

    js:

    jQuery(function(){
        jQuery("#qtyplus").click(function(){     
         jQuery(":text[name='qty']").val( Number(jQuery(":text[name='qty']").val()) + 1 );
        });
        jQuery("#qtyminus").click(function(){
         if(jQuery('#qty').val()>1)
          jQuery(":text[name='qty']").val( Number(jQuery(":text[name='qty']").val()) - 1 );
    
        });
      });
    

    CSS:

    #qtybox button#qtyplus {
        background: url("../images/social_icons/elements.png") no-repeat scroll -268px -223px   
        transparent;
        border: medium none;
        cursor: pointer;
        display: block;
        float: right;
        height: 23px;
        width: 23px;
    }
    

    As you can see, I removed the values of the +'s and -'s - hated how it was rendered!

提交回复
热议问题