jquery realizes the digital plus and minus effect of shopping cart

Source: Internet
Author: User

:

jquery to achieve the shopping cart digital plus and minus effect, the method is simple.

Often write to the shopping cart this piece, and shopping cart is a lot of add and subtract this effect (can copy the HTML code multiple, while supporting), a small summary, the code is as follows:

Html:
<div class= "Gw_num" >   <em class= "Jian" >-</em>   <input type= "text" value= "1" class= "num"/ >   <em class= "Add" >+</em></div>

Css:

. gw_num{border:1px solid #dbdbdb; width:110px;line-height:26px;overflow:hidden;}. Gw_num em{display:block;height:26px;width:26px;float:left;color: #7A7979, border-right:1px solid #dbdbdb; text-align : Center;cursor:pointer;}. Gw_num. Num{display:block;float:left;text-align:center;width:52px;font-style:normal;font-size:14px;line-height: 24px;border:0;}. Gw_num em.add{float:right;border-right:0;border-left:1px solid #dbdbdb;}

Jquery:

$ (document). Ready (function () {//Add the effect $ (". Add"). Click (function () {   var n=$ (this). Prev (). Val ();   var num=parseint (n) +1;   if (num==0) {return;}      $ (this). Prev (). val (num); }); Minus effect $ (". Jian"). Click (function () {   var n=$ (this). Next (). Val ();   var num=parseint (n)-1;   if (num==0) {return}   $ (this). Next (). Val (num);  });
});

jquery realizes the digital plus and minus effect of shopping cart

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.