[英]I can not modify the onchange field of an object cloned javascript
I have a problem when editing the html onchange attribute not let me do it. 我在编辑html onchange属性时遇到问题,但我不这样做。 My code HTML is: 我的代码HTML是:
<table id="insertar">
<tr><td>Producto</td><td>Stock</td><td>Cantidad</td></tr>
<tr><td>
<select id="p1" name="producto[]" onChange="document.getElementById('stock1').value = setStock('p1')" >
<option value="" >---------</option>
<option value="Mexico">Mexico</option>
</select>
</td>
<td><input type="text" id="stock1" value="" name="stock[]" readonly /></td>
<td><input type='text' name='cantidad[]' required /></td></tr>
</table>
<a href="#" onclick="addRow()" >Agregar otro</a>
And my code Javascript is: 我的代码Javascript是:
var _default;
var counter=2;
window.onload=function(){
var x=document.getElementById("insertar").tBodies[0];
_default =x.rows[1].cloneNode(true);
}
function addRow(){
var c=0;
var x=document.getElementById("insertar").tBodies[0];
Array.prototype.slice.call(_default.childNodes, 0).forEach(function(value){
Array.prototype.slice.call(value.childNodes, 0).forEach(function(value1){
if((value1.nodeType === 1) && (c === 0)){
value1.id="p" + counter;
value1.onchange="document.getElementById(\"stock"+counter+"\").value = setStock(\"p"+counter+"\")";
c++;
}else if((value1.nodeType === 1) && (c === 1)){
value1.id = "stock" + counter;
c++;
}
});
});
counter++;
x.appendChild(_default.cloneNode(true));
}
If I work all right, just that I can not change the value onchange 如果我没事,那我就不能更改onchange的价值
I find my answer. 我找到了答案。 I use: 我用:
function addRow(){
var c=0;
var x=document.getElementById("insertar").tBodies[0];
Array.prototype.slice.call(_default.childNodes, 0).forEach(function(value){
Array.prototype.slice.call(value.childNodes, 0).forEach(function(value1){
if((value1.nodeType === 1) && (c === 0)){
value1.id="p" + counter;
value1.setAttribute("onchange","document.getElementById('stock"+counter+"').value = setStock(this.id)");
c++;
}else if((value1.nodeType === 1) && (c === 1)){
value1.id = "stock" + counter;
c++;
}
});
});
counter++;
x.appendChild(_default.cloneNode(true));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.