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:
|
<<: Summary of common docker commands (recommended)
>>: MySQL export of entire or single table data
This article shares the specific code of JavaScri...
Specific method: (Recommended tutorial: MySQL dat...
This article shares the specific code of using ca...
Through the brief introduction in the previous tw...
Recently, when I was doing a practice project, I ...
CSS Operations CSS $("").css(name|pro|[...
In the past, float was often used for layout, but...
wangEditor is a web rich text editor developed ba...
This article shares the specific code of Vue to i...
Get the current date + time (date + time) functio...
Table of contents What are spread and rest operat...
This article example shares the specific code for...
1. What is pip pip is a Python package management...
I am planning to organize the company's inter...
1. Pull the image docker pull registry.cn-hangzho...