当前位置:网站首页>多功能(实现)封装函数
多功能(实现)封装函数
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;
}
关注我,后面会发布更多免费资源,等你来拿。
边栏推荐
猜你喜欢
uni-app 条件编译#ifdef #endif 兼容多个终端
【C】张梁计算器
泰迪杯A题完整版 优化更新(4/23)
PCA feature dimensionality reduction of machine learning + case practice
模拟库函数
游玩数据获取与数据分析、数据挖掘 【2022.5.30】
About the current response, the method getoutputstream() has been called
【C语言_复习_学习第二课】什么是进制?进制之间应该如何转换
Topicexchange switch is simple to use.
机器学习之特征提取(类别特征进行数值化、离散化、文本特征进行数值化)
随机推荐
C语言练习2
POC——DVWA‘s File Inclusion
Bi design: distributed high concurrency epidemic prevention health management system based on vue+socket+redis
数据库实训7【索引与数据完整性约束的创建】
Use of flask
数据分析与数据挖掘实战案例本地房价预测(716):
Actual cases of data analysis and data mining local house price prediction (716):
【C语言—零基础第十四课】变量的作用域与存储类
ModelArts第二次培訓筆記
645. 错误的集合
Use of transactions - Django, SQL tools
读论文《SNUNet-CD: A Densely Connected Siamese Network for Change Detection of VHR Images》
User management - paging
【C】 Beam calculator
Redis installation
关于New_Online_Judge_1081_哥德巴赫猜想的思考
Modelarts second training notes
Simple use of directexchange switches.
Three high concurrency methods to realize I++
Harmonyos third training notes