日期:2014-05-16  浏览次数:20371 次

请教一问题!
function   addfile()
{
var   op   =   document.createElement( 'input ');
op.name= 't1 ';
op.type= 'file ';
op.id= 't1 ';
document.body.appendChild(op);
}
</script>
<button   onclick= 'addfile() '> 附件 </button>

这样虽说可以插入file可是,它始终只能插在本来有的form之外
这对以后表单提交带来很多不便!
如果我欲想将file新增在
<form   name= "form1 "   id= "form1 "   action= " "   method= "post ">
</form> 之间如何实现呢?请指教,谢谢!


------解决方案--------------------
function addfile()
{
var op = document.createElement( 'input ');
op.name= 't1 ';
op.type= 'file ';
op.id= 't1 ';
document.getElementById( 'form1 ').appendChild(op);//ocument.body.appendChild(op);
}


------解决方案--------------------
document.getElementById( 'form的id ').appendChild(op);