从javascript insertCell HTML输入标记传递this.value
passing this.value from javascript insertCell HTML input markup
我有一个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'>❌</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
相关文章:
- 将php值传递给点击(getFunction(this.value))问题
- Javascript:this.value 函数不起作用
- Javascript onchange(this.value,this.value)在ipad上不起作用
- this.value在<td>标记显示未定义
- 从javascript insertCell HTML输入标记传递this.value
- 为什么我需要将“var value = val;”更改为“this.value = val;”,这样我就不会收到“未定义
- JQuery 将输入框值设置为 this.value onclick
- this.value 在从 onchange 事件调用函数时显示为 undefind
- 将 this.value 传递给 JS 中的函数,然后更改该值
- 流星:如何使用模板事件检索“{{this}}-value”
- javascript this.value没有'不起作用
- this.value 返回带有值的括号
- AngularJS-将this.value传递到函数中
- 什么是'this.value'经典ASP Javascript参考中的平均值
- onkeyup="this.value = this.value.replace(/,/g,'.
- HTML表单,onclick="this.disabled=true;this.value='发送中,
- JavaScript- this value
- 在requestAnimationFrame中设置正确的this-value
- 如何使用onchange="函数(this.value)
- 通过“this.value"to addEventListener功能