let contents = [];
function sss(e){
var flag = true;
var zhi = e.getAttribute("value");
var num = e.getAttribute("money");
var arr_tr =document.getElementById("table2").getElementsByTagName("tr");
let i;
for(i=0 ; i<arr_tr.length ; i++){
var td = arr_tr[i].firstElementChild.innerHTML;
//重复点菜,修改数量和金钱
if(td == zhi){
flag = false;
//个数
var count = arr_tr[i].firstElementChild.nextElementSibling.nextElementSibling;
var sum = count.innerHTML = parseFloat(count.innerHTML) + 1;
//金钱数
var qian = arr_tr[i].firstElementChild.nextElementSibling.innerHTML = sum * num;
break;
}
}
if(flag){
let tbody1 = document.getElementById("tbody1");
var tr = document.createElement("tr");
//名称
var td1 = document.createElement("td");
td1.innerHTML = `${zhi}`;
//价钱
var td2 = document.createElement("td");
td2.innerHTML = `${num}`;
//数量
var td3 = document.createElement("td");
td3.innerHTML = `1`;
//操作
var td4 = document.createElement("td");
td4.innerHTML = `<button class="btn btn-sm btn-warning" οnclick=shanchu(this)>删除</button>`;
//插入
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
tr.appendChild(td4);
tbody1.appendChild(tr);
}
}
//删除
function shanchu(obj){
obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
}
暂时没有评论,来抢沙发吧~