javascript develops shopping cart function to implement plus sign function

Let’s take a look at the html part of the code:

      
名称 单价 数量 总价
手表 1999 - + 1999
手机 2000 - + 2000

As shown in the above code, we have 2 products. If we add a product each time and write the plus and minus function, then the code will be There are too many. Although it is possible, it is not advisable, so we can make a function below

Let us analyze, what are the parameters of the function?

In fact, if we do the addition and subtraction function, and then the total price changes, what we need is 3 parameters, unit price, total price, quantity

Look at the cell displaying the unit price in the above code, id is price total price cell, id is total id of the first product text box is count

Next, we look at the cell code:

      
名称 单价 数量 总价
手表 1999 - + 1999
手机 1999 - + 1999

As above code, we add The minus sign is bound to a click event, which contains three parameters: product unit price price and price_1 total price total and total_1 quantity count and count_1

Let’s implement the plus sign function

Let’s take a look at the following complete code: Let’s see how the effect is achieved

       
名称 单价 数量 总价
手表 1999 - + 1999
手机 1999 - + 1999

Look at the above example, no matter how many products I have, if I click the plus sign, the price will be different, and the total price will be different, so use this The method will be more convenient and simpler

Continuing Learning
||
名称 单价 数量 总价
手表 1999 - + 1999
手机 1999 - + 1999

submit Reset Code
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!