日期:2014-05-17  浏览次数:21145 次

初学的简单问题。
我看到很多网站上有点一个按钮就能增加一行输入框是怎么弄的呢?
就象邮件发送系统里点增加附件就多一个框来输入附件的路径。在点增加又多一行来发多个附件呢?

------解决方案--------------------
<script>
function addtext()
{
var op = document.createElement( 'input ');
op.id= 't1 ';
document.body.appendChild(op);
}

<script>
<button onclick= 'addtext() '> addtext </button>
------解决方案--------------------
<form name= "form1 " id= "form1 " action= " " method= "post ">
<input type= "button " value= "附件 " onClick= "return showdiv(); ">
<div id= "a1 " style= "display:none; "> <input type= "file " name= "file1 "> </div>
<div id= "a2 " style= "display:none; "> <input type= "file " name= "file2 "> </div>
<div id= "a3 " style= "display:none; "> <input type= "file " name= "file3 "> </div>
<div id= "a4 " style= "display:none; "> <input type= "file " name= "file4 "> </div>

</form>
<script language= "javascript ">
function showdiv(){
for(i=1;i <5;i++)
{if(eval( "a "+i).style.display== "none "){
eval( "a "+i).style.display= "block ";
break;
}
}
}
</script>
------解决方案--------------------
function addfile()
{
var login=0;
var br = document.createElement( 'br ');
document.body.appendChild(br);
var aa = document.getElementsByTagName( "input ");
for(var i=0;i <aa.length;i++)
{
if(aa[i].type== "file "){
var op = document.createElement( 'input ');
op.name= 't '+(aa.length-i+1);
op.type= 'file ';
op.id= 't '+(aa.length-i+1);
document.body.appendChild(op);
document.getElementById( "kkk ").innerHTML=op.name
login=1;
break
}
}
if(login==0)
{
var op = document.createElement( 'input ');
op.name= 't1 ';
op.type= 'file ';
op.id= 't1 ';

document.body.appendChild(op);
document.getElementById( "kkk ").innerHTML=op.name
return false;
}
}
</script>
<button onclick= 'addfile() '> 附件 </button>
<div id= "kkk "> </div>
------解决方案--------------------
楼上的已经说了~!
------解决方案--------------------
是不是要这种效果?
<script>
function addfile()
{
var login=0;
var aa = document.getElementsByTagName( "input ");
for(var i=0;i <aa.length;i++)
{
if(aa[i].type== "file "){
var op = document.createElement( 'input ');
var op2 = document.createElement( 'tr ');
var op3 = document.createElement( 'td ');
var op21 = document.createElement( '/tr ');
var op31 = document.createElement( '/td ');
op.name= 't '+(aa.length-i+1);
op.type= 'file ';
op.id= 't '+(aa.length-i+1);
op2.id= 'tr '+(aa.length-i+2);
op3.id= 'td '+(aa.length-i+2);