日期:2014-05-20  浏览次数:20419 次

js删除html控件
我在一个页面中自由添加多个控件,要怎么样才能动态删除呢。哪位大哥指点一下,感激不尽!
function   addFile()  
        {  
              var   str   =   ' <INPUT   type= "file "   size= "50 "   NAME= "File "> '  
              document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",str)  
        }
function   delFile()  
        {  
这里应该怎么样写呢....
        }

------解决方案--------------------
function AddAttachments()
{

document.getElementById( 'attach ').innerText = "继续添加附件 ";
tb = document.getElementById( 'attAchments ');
newRow = tb.insertRow();
newRow.insertCell().innerHTML = " <input class= 'ButtonCss ' name= 'File ' size= '50 ' type= 'file '> &nbsp;&nbsp; <input class= 'ButtonCss ' type=button value= '删除 ' onclick= 'delFile(this.parentElement.parentElement.rowIndex) '> ";
}
function delFile(index)
{
document.getElementById( 'attAchments ').deleteRow(index);
tb.rows.length > 0?document.getElementById( 'attach ').innerText = "继续添加附件 ":document.getElementById( 'attach ').innerText = "继续添加附件 ";
}
------解决方案--------------------
function addFile()
{
var str = ' <INPUT type= "file " size= "50 " Name= "File "> '
document.getElementById( 'MyFile ').insertAdjacentHTML( "beforeEnd ",str)
}
function delFile()
{
var objArr=document.getElementById( 'MyFile ').getElementsByTagName( "input ");
objArr[objArr.length-1].removeNode(true);
}