appendQuantity(cell,row){
let oldel = cell.children[0]
if (cell.children.length > 1) {
return
} 防止点击cell再次创建input输入框
var cellInput = document.createElement("input");
cellInput.setAttribute("type", "Number");
cellInput.setAttribute("class", "edit");
cellInput.setAttribute("min", "0");
cellInput.value = cell.children[0].innerText;
cellInput.style.width = "100%";
cellInput.style.border = "none";
cellInput.style.backgroundColor = "transparent";
cellInput.style.paddingLeft = "10px";
cellInput.style.outline = "none";
oldel.style.display = " none";
cell.appendChild(cellInput);
cellInput.focus(); //主动聚焦
cellInput.onblur = function (val) {
console.log('-------------')
console.log(cellInput.value)
if (cellInput.value != '') {
row.quantity = cellInput.value
if (row.price != '') {
row.total = floatMultiply(row.price, row.quantity)
} else {
if (row.total != '') {
row.price = floatDivide(row.total, row.quantity)
}
}
}
//oldel.innerHTML = cellInput.value;
console.log(row)
oldel.style.display = "block";
cell.removeChild(cellInput);
//cell.nextElementSibling.emit("click")
//event.target.innerHTML = cellInput.value;
};
const that =this
cellInput.onkeyup= function (ev){
if(cellInput.value==''){
alert('1')
}
console.log(ev)
console.log('cellInput.value')
console.log(cellInput.value)
if(ev.keyCode==13) {
console.log("回车")
console.log(cell)
console.log(row)
if (cell.nextSibling){ //如果node节点的下一个兄弟节点存在即条件为真,则退出此函数,并递归,参数变为node节点的下一个兄弟节点。
that.appendPrice(cell.nextSibling,row)
}
}
}
},
|