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);

解决方案 »

  1.   

    日 点急了。这段代码造出来的input 元素 始终没有 text属性!也就是说btnDelete.setAttribute('type', 'button'); 类似这种代码始终没有作用。为什么
      

  2.   


    IE下要用 document.getElementById("ID").TYPE=VALUE;
    FF下可以用 document.getElementById("ID").setAttribute(TYPE,VALUE)
      

  3.   

    是 btnDelete.setAttribute('type', 'button'); 不起作用?代码测试下来可以显示按钮的
    如果是定义事件的话,用
     btnDelete.onclick = function(){}
      

  4.   

    You must perform a second step when using createElement to create the input element. The createElement method generates an input text box, because that is the default input type property. To insert any other kind of input element, first invoke createElement for input, then set the type property to the appropriate value in the next line of code. 
    ——DHTML参考手册L@_@K
    <!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>
    Web 开发常用手册JScript语言参考.rar
    http://download.csdn.net/source/308916DHTML参考手册.rar
    http://download.csdn.net/source/308913样式表中文手册.chm
    http://download.csdn.net/source/304124
      

  5.   

    <body>
    <script>
    var txtprojectName = document.createElement('input');
    txtprojectName.type="button"
    document.body.appendChild(txtprojectName)
    </script>
      

  6.   


    var sb = "<TR id=tr_"+rowIndex+">"+
    "<TD id=id_index" + rowIndex + ">" + rowIndex + "</TD>" +
    "<TD><INPUT id=txt_add_PaymentPlanName" + rowIndex + " type=text></TD>" +
    "<TD><INPUT id=txt_add_MoneyInPlan" + rowIndex + " onkeypress=\"return noNumbers(this,event,true)\" onkeyup=CompleteTotalMoney() onpaste=\"return false\" type=text></TD>" +
    "<TD><INPUT id=txt_add_DateInPlan" + rowIndex + " onclick=setday(this) readOnly type=text></TD>" +
    "<TD><INPUT id=ckb_add_IsAwoke1 value=" + rowIndex + " type=checkbox></TD>" +
    "<TD><INPUT id=btn_add_Delete"+rowIndex+" onclick=deleteTR("+rowIndex+") value=删除 type=button /></td></tr>";
                    $("#tb_paymentplan").append(sb);
    执行这样一段代码,再alert($("#tb_paymentplan").html());弹出来的代码有些input元素居然还是没有type
      

  7.   

    确实,IE 7 下没问题滴,估计 IE 8 应该也可以,
    如果是 IE 6 就要用 btnDelete.type = 'button';