从javascript insertCell HTML输入标记传递this.value

passing this.value from javascript insertCell HTML input markup

本文关键字:this value javascript insertCell HTML 输入      更新时间:2023-11-28

我有一个javascript函数,它创建一个表并插入一个带有insertCell(0); 的单元格

单元格内部是一个html表单输入,它调用另一个函数onKeyUp,我将4个参数传递给它。最后一个参数是输入this.value的值。此值始终作为未定义值传递。当用户更新数量时,有没有办法得到这个值?

我不能使用ID选择器,因为每次向购物车添加商品时都会创建tr。

我发布了整个功能,但这是问题线。

这不起作用。。。

cell1.innerHTML="<input type='text' onKeyUp='updateQty("+posItem.id+",'""+posItem.color+"'",'""+posItem.size+"'","+this.value+")' name='qty' value='"+posItem.qty+"' class='textfield'/>";

这是的全部功能

function addToPosCart(posItem) {
    posCart.push(posItem);
    var table=document.getElementById("cart_table");
    var tr = table.insertRow(-1);
    tr.className = 'row';
    tr.setAttribute('row_id',posItem.id);
    tr.setAttribute('color',posItem.color);
    var totalPrice = posItem.price * posItem.qty;
    var cell1=tr.insertCell(0);
    var cell2=tr.insertCell(1);
    var cell3=tr.insertCell(2);
    var cell4=tr.insertCell(3);
    var cell5=tr.insertCell(4);
    var cell6=tr.insertCell(5);
    var cell7=tr.insertCell(6);
    cell1.innerHTML="<input type='text' onKeyUp='updateQty("+posItem.id+",'""+posItem.color+"'",'""+posItem.size+"'","+this.value+")' name='qty' value='"+posItem.qty+"' style='width:30px' class='textfield input_qty'/>";
    cell2.innerHTML="<span style='font-size:16px;font-weight:bold;'>"+posItem.name+"</span><br>"+posItem.color +" "+posItem.size;
    cell3.innerHTML="$"+posItem.price.toFixed(2);
    cell4.innerHTML="<input type='text' name='dis_dollars' value='"+posItem.disDollars+"' style='width:30px' class='textfield'/>";
    cell5.innerHTML="<input type='text' name='dis_percent' value='"+posItem.disPercent+"' style='width:30px' class='textfield'/>";
    cell6.innerHTML="$"+totalPrice.toFixed(2);
    cell7.innerHTML="<a onclick='deleteItem(this.rowid)' style='height:22px;width:23px;padding:1px 0 0 0px;'class='button_black'>&#10060;</a>";
    updateTotals();
}

它应该是

cell1.innerHTML = "<input type='text' onKeyUp='updateQty(" + posItem.id + ",'"" + posItem.color + "'",'"" + posItem.size + "'",this.value)' name='qty' value='" + posItem.qty + "' style='width:30px' class='textfield input_qty'/>";

演示:Fiddle