您现在的位置是:首页 > 电脑技术查询 > web开发

请问一有关问题

编辑:chaxungu时间:2022-10-02 23:21:31分类:web开发

请教一问题!
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);