当前位置:网站首页>多功能(实现)封装函数
多功能(实现)封装函数
2022-07-17 05:04:00 【共创splendid--与您携手】
一,添加商品信息
//添加商品信息
addcart(title,price){
var goods=this.goods;
//利用对象的形式添加值
var obj={id:0,title:title,price:price,sue:1};
obj.id=goods.length+1;
//在末尾添加
goods.push(obj);
//刷新页面
this.setGoods();
}
二,删除单行
//单行删除
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;
}
三,全选影响内部复选及所有复选影响全选
//部分选择影响全选
teselectAll(){
var flag = true;
for(var i=0;i<this.Checkbox.length;i++){
if(!this.Checkbox[i].checked){
flag=false;
}
}
this.selectAll.checked=flag;
}
//全选影响部分选择
selectAllt(e) {
var checked = e.target.checked;
console.log(checked);
for (var i = 0; i < this.Checkbox.length; i++) {
this.Checkbox[i].checked = checked;
}
}四,清空数据
//清空购物车
delalltemp(){
this.goods=[];
this.setGoods();
}
五,更改数据信息
//更改数据 再addevent()外边写
editData(id, key, value) {
var goods = this.goods;
for (var i = 0; i < goods.length; i++) {
//判断更改的是哪一行的数据
if (goods[i].id == id) {
goods[i][key] = value;
}
}
}
六,获取商品个数, 添加产品复选框(项), 计算总费用
Amount() {
//获取页面信息
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;
}
关注我,后面会发布更多免费资源,等你来拿。
边栏推荐
猜你喜欢

es6新增-数组/对象的解构赋值

es6新增-运算符的扩展

elment-ui使用方法

Use of transactions - Django, SQL tools

mysql数据库实验实训6,数据视图(详细)

这么6的刷题网站你不会没听说过吧?你已经out 了?

卷积神经网络

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)

Cve-2017-12635 CouchDB vertical privilege bypass vulnerability recurrence

Convolutional neural network
随机推荐
【LeetCode——编程能力入门第二天】运算符(位1的个数/整数的各位积和之差)
C语言 带你 手撕 通讯录
PyGame installation -requirement already satisfied
Teddy Cup title a full version optimization update (4/23)
Harmonyos third training notes
【C语言—零基础_学习_复习_第五课】基本运算符的运算性质
Install MySQL
(精讲)Es6 剩余参数,ES6内置对象,模板字符串内容(详例宝典)及灵活运用项目的实战案例
uniapp 使用uview实现折叠面板
【C语言—零基础第十三课】字符串的奥秘
PAT乙级1002:写出这个数
User management - paging
Bi design: distributed high concurrency epidemic prevention health management system based on vue+socket+redis
Cve-2022-23131 ZABBIX SAML SSO authentication bypass vulnerability
Use of transactions - Django, SQL tools
Redis installation
Class object automatic injection attribute operation tool
Elment UI usage
02 Bar _ Recommandation de film (basée sur le contenu) Portrait de l'utilisateur
简单快速建立pytorch环境YOLOv5目标检测 模型跑起来(超简单)