var n=0;
function addma(){
var idma= document.createElement('input');
idma.setAttribute("type", "text");
idma.setAttribute('id','idma'+n);
var idtien= document.createElement('input');
idtien.setAttribute("type", "text");
idtien.setAttribute('id','idtien'+n);
var idbr= document.createElement('br');
var kqphu= document.createElement('label');
//kqphu.setAttribute("type", "text");
kqphu.setAttribute("id", "kqphu"+n);
var bid=document.getElementById('idneedadd');
bid.appendChild(idma);
bid.appendChild(idtien);
bid.appendChild(kqphu);
bid.appendChild(idbr);
n++;
}
function tinhtien(){
var ketqua=0;
for(var i=0; i< n; i++)
{
var idma=document.getElementById('idma'+i).value;
var idtien=document.getElementById('idtien'+i).value;
var kqphu=document.getElementById('kqphu'+i);
var kq=idma*idtien;
ketqua=kq+ketqua;
kqphu.innerHTML='kq thu '+i+'la '+kq+' ';
}
alert("ket qua: "+ketqua);
}
function freset(){
<!-- Codes by Quackit.com -->
location.reload(true);
}
</script>
</head>
<body>
<div id="idneedadd"></div>
<input type="button" name="ketqua" value="ket qua" onclick="tinhtien()" />
<input type="button" name="add" value="add" id="add" onclick="addma()"/>
<input type="button" name="reset" value="reset" id="reset" onclick="freset()"/></body>
No comments: