javascript develops shopping cart function to implement minus sign function

In the previous section, we have completed the function of the plus sign. Click the minus sign. It is actually very simple.

We copy the js code of the plus sign, and then change the plus sign to the minus sign. That's it, but there will be a problem. If we keep reducing, we can reduce it to a negative number, which does not meet our requirements.

So, we must first make a judgment. The code is as follows:

Same code as above

First get the total unit price quantity, and then judge. When the number is greater than 1, we can subtract it. When the number is not greater than 1, we give a default value of 1

The complete code is as follows:

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

In this way, our addition and subtraction have been completed

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!