동적으로 생성 된 텍스트 상자에 추가됩니다하지 않는 것 같습니다 ...하지만 제대로 작동 나던 ....자바 스크립트 이벤트는 내가 자바 스크립트에서 동적으로 추가 텍스트 상자에 대한 자바 스크립트를 onKeyUp에 추가
var cell4 = row.insertCell(3);
cell4.setAttribute('align','center')
var e3 = document.createElement('input');
e3.type = 'text';
e3.name = 'txtqt' + iteration;
e3.id = 'txtqt' + iteration;
e3.onkeyup = totalAmount(event,this,'tblsample');//Adding this lines doesnt work
e3.size = 10;
cell4.appendChild(e3);
그러나 때 나는 일
e3.onkeyup = totalAmount;
... 사용 여기 내 자바 스크립트 함수,
기능 totalAmount이다 (예, OBJ, tblid) {
,var tbl = document.getElementById(tblid);
//alert(tbl);
var tblRows = tbl.rows.length;
//alert(tblRows);
var result =0;
var str1;
if (obj != null) {
str1 = obj.id;
} else {
str1 = this.id;
}
var lastChar = str1.substring(5,str1.length);
//alert(lastChar);
if(str1=='txtqt'+lastChar)
{
var str2 = 'txtup'+lastChar;
var str3 = 'txtAmount'+lastChar;
var txtDeduct = document.getElementById(str1).value;
var txtAmt = document.getElementById(str2).value;
var txtTotal = document.getElementById(str3);
var totRes = txtAmt*txtDeduct;
//var res = formatNumber(totRes,2)
txtTotal.value = totRes.toFixed(2)
document.getElementById('txttotAmount').value = totRes.toFixed(2);
for(i=1;i<=tblRows;i++)
{
//alert(tblRows);
txtTotID = 'txtAmount'+i;
if(document.getElementById(txtTotID).value!='')
{
result =parseFloat(result) + parseFloat(document.getElementById(txtTotID).value);
//var res= formatNumber(result,2)
document.getElementById('txtTotalAmount').value = result.toFixed(2);
document.getElementById('txttotAmount').value = result.toFixed(2);
//document.getElementById('txtTotalAmount').value = result;
}
}
}
}
@sparkyfied '이벤트가 정의되지 않았습니다.'오류 ... –
@chandru_cp 죄송합니다. try addEvent (e3, 'keyup', function (event) {totalAmount (event, this, 'tblsample');}); – jamesmhaley
@chandru_cp 해당 수정 사항을 반영하도록 위 게시물을 업데이트했습니다. – jamesmhaley