87,910
社区成员
发帖
与我相关
我的任务
分享
var tbody = document.getElementById('tb_paymentplan');
var tr = document.createElement('tr');tr.setAttribute('id', 'tr_' + rowIndex);
//第一列 索引
var td1 = document.createElement('td'); td1.setAttribute('id', 'id_index' + rowIndex);
td1.appendChild(document.createTextNode(rowIndex.toString()));
tr.appendChild(td1);
//第二列
var td2 = document.createElement('td');
var txtprojectName = document.createElement('input');
txtprojectName.setAttribute('type', 'text'); txtprojectName.setAttribute('id', 'txt_add_PaymentPlanName' + rowIndex);
td2.appendChild(txtprojectName);
tr.appendChild(td2);
//第三列
var td3 = document.createElement('td');
var txtMoneyInPlan = document.createElement('input');
txtMoneyInPlan.setAttribute('type', 'text'); txtMoneyInPlan.setAttribute('id', 'txt_add_MoneyInPlan' + rowIndex);
txtMoneyInPlan.setAttribute('onkeypress', 'return noNumbers(this,event,true)');txtMoneyInPlan.setAttribute('onkeyup', 'CompleteTotalMoney()');txtMoneyInPlan.setAttribute('onpaste', 'return false');
td3.appendChild(txtMoneyInPlan);
tr.appendChild(td3);
var td4 = document.createElement('td');
var txtDateInPlan = document.createElement('input');
txtDateInPlan.setAttribute('type', 'text'); txtDateInPlan.setAttribute('id', 'txt_add_DateInPlan' + rowIndex); txtDateInPlan.setAttribute('onclick', 'setday(this)');
txtDateInPlan.setAttribute('readonly','readonly');
td4.appendChild(txtDateInPlan);
tr.appendChild(td4);
var td_isawoke = document.createElement('td');
var ckbIsawoke = document.createElement('input');
ckbIsawoke.setAttribute('type', 'checkbox'); ckbIsawoke.setAttribute('id', 'ckb_add_IsAwoke' + rowIndex); ckbIsawoke.setAttribute('value', '1');
td_isawoke.appendChild(ckbIsawoke);
tr.appendChild(td_isawoke);
var td5 = document.createElement('td');
var btnDelete = document.createElement('input');
btnDelete.setAttribute('type', 'button'); btnDelete.setAttribute('id', 'btn_add_Delete' + rowIndex); btnDelete.setAttribute('value', '删除'); btnDelete.setAttribute('onclick', 'deleteTR(' + rowIndex + ')');
td5.appendChild(btnDelete);
tr.appendChild(td5);
rowIndex = rowIndex + 1;
tbody.appendChild(tr);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> new document </title>
<meta name="generator" content="editplus" />
<meta name="author" content="" />
<meta name="keywords" content="" />
<meta name="description" content="" />
</head>
<body>
<script type="text/javascript">
<!--
var btnDelete = document.createElement('input');
btnDelete.type = 'button';
btnDelete.setAttribute('id', 'btn_add_Delete');
btnDelete.setAttribute('value', '删除');
btnDelete.onclick = function() {
alert(this.id);
};
document.body.appendChild(btnDelete);
//-->
</script>
</body>
</html>
IE下要用 document.getElementById("ID").TYPE=VALUE;
FF下可以用 document.getElementById("ID").setAttribute(TYPE,VALUE)