日期:2014-05-18  浏览次数:20843 次

如何在单元格里面动态添加文本框? 求助
在表格里面动态添加文本框可以实现:
<input   name= "button "   type=button   onClick= 'additem( "tb ") '   value= "添加> > ">
  <table   id= "tb ">
  </table>
<script   language= "javascript ">
function   additem(id)
{
    var   row,cell,str;
    row   =   eval( "document.all[ "+ ' " '+id+ ' " '+ "] ").insertRow();
    if(row   !=   null   )
          {
                cell   =   row.insertCell();
                str= " <input   type= "+ ' " '+ "text "+ ' " '+ "   name= "+ ' " '+ "StuName "+ ' " '+ "> <input   type= "+ ' " '+ "button "+ ' " '+ "   value= "+ ' " '+ "删除 "+ ' " '+ "   onclick= 'deleteitem(this, "+ ' " '+ "tb "+ ' " '+ "); '> "
      cell.innerHTML=str;
            }
}
function   deleteitem(obj,id)
{
    var   rowNum,curRow;
    curRow   =   obj.parentNode.parentNode;
    rowNum   =   eval( "document.all. "+id).rows.length   -   1;
    eval( "document.all[ "+ ' " '+id+ ' " '+ "] ").deleteRow(curRow.rowIndex);
}
</script>

但是我要是想在表格的单元格里动态添加,应该怎么实现呢?


------解决方案--------------------
<td name= "inputWrapper "> </td>

<script language= "javascript ">
function addInput() {
document.getElementsByName( "inputWrapper ").innerHTML = " <input typpe= 'text '> ";
}
</script>