当前位置:网站首页>Multifunctional (Implementation) encapsulation function
Multifunctional (Implementation) encapsulation function
2022-07-19 05:12:00 【Create splendid -- hand in hand with you】
One , Add product information
// Add product information
addcart(title,price){
var goods=this.goods;
// Adding values in the form of objects
var obj={id:0,title:title,price:price,sue:1};
obj.id=goods.length+1;
// Add... At the end
goods.push(obj);
// Refresh the page
this.setGoods();
}
Two , Delete a single line
// Single row deletion
dongter(id){
var goods=this.goods;
var index=0;
for(var i=0;i<goods.length;i++){
if(goods[i].id==id){
index=i;
}
}
goods.splice(index,1);
// this.goods=goods;
}
3、 ... and , Select all affects the internal check and all checks affect select all
// Partial selection affects full selection
teselectAll(){
var flag = true;
for(var i=0;i<this.Checkbox.length;i++){
if(!this.Checkbox[i].checked){
flag=false;
}
}
this.selectAll.checked=flag;
}
// Select all affects partial selection
selectAllt(e) {
var checked = e.target.checked;
console.log(checked);
for (var i = 0; i < this.Checkbox.length; i++) {
this.Checkbox[i].checked = checked;
}
}Four , Empty data
// empty cart
delalltemp(){
this.goods=[];
this.setGoods();
}
5、 ... and , Change data information
// Change data Again addevent() Write outside
editData(id, key, value) {
var goods = this.goods;
for (var i = 0; i < goods.length; i++) {
// Determine which row of data is changed
if (goods[i].id == id) {
goods[i][key] = value;
}
}
}
6、 ... and , Number of products obtained , Add product check box ( term ), Calculate the total cost
Amount() {
// Get page information
var goods = this.goods;
var sum = 0;
var count = 0;
for (var i = 0; i < goods.length; i++) {
if (this.Checkbox[i].checked) {
sum = sum + goods[i].price * goods[i].sue;
count++;
}
}
this.amount.innerHTML = sum;
this.contNode.innerHTML = count;
}
Pay attention to me , More free resources will be released later , Wait for you to pick up .
边栏推荐
猜你喜欢

Uniapp uses uview to realize folding panel

微信小程序获取年月日周及早上、中午、晚上

How to upload qiniu cloud

First training notes of moderlarts

Harmonyos third training notes

IText modify PDF Text

Asynchronous data SMS verification code

The code of yolov5 model for pest identification in Title A of the 10th Teddy cup data mining challenge (has been run through, original works, continuously updated)

【C】 Beam calculator

MD5 password encryption
随机推荐
第十届泰迪杯数据挖掘挑战赛A题害虫识别YOLOv5模型代码(已跑通,原创作品,持续更新)
【2022第十届‘泰迪杯’挑战赛】A题:害虫识别完整版(大致思路。详细过程和代码以及结果csv在压缩包中)
uni-app 条件编译#ifdef #endif 兼容多个终端
【C语言_复习_学习第二课】什么是进制?进制之间应该如何转换
【C语言—零基础_学习_复习_第四课】数据类型及其运算
Applet cloud development upload pictures to cloud storage
Interface parameters return encapsulated class result
【C】 Beam calculator
(精讲)Es6 剩余参数,ES6内置对象,模板字符串内容(详例宝典)及灵活运用项目的实战案例
使用Echars实现水滴状、环形图、分割图、堆叠、组织架构图、地图轮廓等图表
IDL MODIS 生成查找表
[2022 10th Teddy Cup Challenge] Title A: complete version of pest identification (general idea. Detailed process and code and results CSV in compressed package)
C语言练习题
IText modify PDF Text
STL容器——set集合的应用
PyGame aircraft War 1.0 (step + window no response problem)
es6新增-let和const (var的缺点&let及const)
6S参数
Use of flask
微信小程序wx.setClipboardData复制文本