JavaScript to implement a simple shopping form

JavaScript to implement a simple shopping form

This article shares the specific code of JavaScript to implement a simple shopping form for your reference. The specific content is as follows

HTML code:

<table border="" cellspacing="0" cellpadding="1">
   <tr style="background-color: #0099cc;">
    <td><input type="checkbox" class="all"/></td>
    <td style="text-align: center; width: 200px;">Products</td>
    <td style="color: white; width: 70px; height: 30px; text-align: center;">Price</td>
   </tr>
   <tr class="zuida">
    <td><input type="checkbox" class="lla"/></td>
    <td>Apple</td>
    <td style="text-align: center;" class="zongji">8000</td>
   </tr>
   <tr class="zuida">
    <td><input type="checkbox" class="lla"/></td>
    <td>Banana</td>
    <td style="text-align: center;" class="zongji">5000</td>
   </tr>
   <tr class="zuida">
    <td><input type="checkbox" class="lla"/></td>
    <td>Pear</td>
    <td style="text-align: center;" class="zongji">2000</td>
   </tr>
   <tr class="zuida">
    <td><input type="checkbox" class="lla"/></td>
    <td>Vegetables</td>
    <td style="text-align: center;" class="zongji">2000</td>
   </tr>
   <tr>
    <td colspan="3">The total price is: <span class="zongjia">0</span> yuan</td>
   </tr>
</table>

JQ code:

<script src="jquery-3.6.0.min.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript">
   $(function(){
     $(".all").change(function(){
      var value = $(this).prop("checked")
      $(".lla").prop("checked",value)
      zongjia()
     })
     $(".lla").click(function(){
      var chang1=$(".lla").length;
      var chang2=$(".lla:checked").length;
      if(chang1===chang2){
       $(".all").prop("checked",true)
      }else{
       $(".all").prop("checked",false)
      }
      zongjia()
     })
     $(".lla").change(function(){
      zongjia()
     })
     function zongjia(){
      var xuan=$(".lla:checked").parents(".zuida");
      var num=0;
      xuan.each(function(index,rom){
       var xuanzhi=$(rom).find(".zongji").text()*1;
       num+=xuanzhi;
      })
      $(".zongjia").text(num);
     }
    })
</script>

Finished product picture:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Vuejs teaches you step by step to write a complete shopping cart example code
  • js shopping cart implementation ideas and code (personally feel good)
  • Writing a simple shopping cart function in JavaScript
  • Javascript detailed code to implement shopping cart function
  • js implements a simple shopping cart with pictures and codes
  • Jsp+Servlet to realize shopping cart function
  • Javascript manipulates Cookies to implement shopping cart program
  • Simple front-end js+ajax shopping cart framework (beginner's guide)
  • Native js simulation Taobao shopping cart project practice
  • js to achieve shopping cart addition and subtraction effects

<<:  Summary of common docker commands (recommended)

>>:  MySQL export of entire or single table data

Recommend

Thoughts on copy_{to, from}_user() in the Linux kernel

Table of contents 1. What is copy_{to,from}_user(...

Solution to the problem of repeated triggering of functions in Vue project watch

Table of contents Problem description: Solution 1...

Using CSS3 to create header animation effects

Netease Kanyouxi official website (http://kanyoux...

MySQL database introduction: detailed explanation of database backup operation

Table of contents 1. Single database backup 2. Co...

JavaScript deshaking and throttling examples

Table of contents Stabilization Throttling: Anti-...

CSS margin overlap and how to prevent it

The vertically adjacent edges of two or more bloc...

MySQL query_cache_type parameter and usage details

The purpose of setting up MySQL query cache is: C...

The best way to start a jar package project under Centos7 server

Preface Everyone knows how to run a jar package o...

You Probably Don’t Need to Use Switch Statements in JavaScript

Table of contents No switch, no complex code bloc...

Perfect solution for theme switching based on Css Variable (recommended)

When receiving this requirement, Baidu found many...

ElementUI component el-dropdown (pitfall)

Select and change: click to display the current v...

Some tips on using the HTML title attribute correctly

If you want to hide content from users of phones, ...

Write a simple calculator using JavaScript

The effect is as follows:Reference Program: <!...