首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

怎么实现这个功能啊

2011-12-15 
如何实现这个功能啊我想用一个文本域接收用户输入的信息,当用户输入信息后,点添加按纽又显示一个文本域.就

如何实现这个功能啊
我想用一个文本域接收用户输入的信息,当用户输入信息后,点添加按纽又显示一个文本域.就是类似于上传多个文件那种功能,当用户点添加后又可以看到另一个文本域.

[解决办法]
<script language= "javascript ">
var StraddItem= " ";
var ItemNo=1;
function AddItm()
{
var mybag= "Mybag "+(ItemNo-1);
StraddItem= " <table id=TblItm "+ItemNo+ " WIDTH=100% BORDER=0 CELLSPACING=1 CELLPADDING=1 BORDERCOLOR=red> <TR> <TD COLSPAN=6 > &nbsp </TD> </TR> <tr colspan=6 height=1 align=center> <td align=center colspan=13 width=100% bgcolor=mistyrose> 选中 <INPUT TYPE=CHECKBOX name=chkAppIt "+ ItemNo + " value=Y> &nbsp; "+ " 文件 "+ ItemNo + ": <input type=file name=file "+ ItemNo + " size=50> </td> </tr> <TR> <TD COLSPAN=6 > &nbsp </TD> </TR> </table> <div id=mybag "+ItemNo+ " > </div> ";
document.all(mybag).innerHTML=StraddItem;
ItemNo++;
}
function DelItm()
{
var i;
var bSel;
var strURL;

for(i=1;i <ItemNo;i++)
{
chkAppItx= "chkAppIt "+i;
TblItmx= "TblItm "+i;
if (document.all(chkAppItx).checked==true)
{document.all(TblItmx).style.display= "none ";
bSel=true;
}
}
if (bSel != true) {alert( "请首先选中您要删除的文件行 ") ; return false; }
else return true;
}
</script>
[解决办法]
随便写了个,你试试看
<script>
function moreArea()
{
document.all.Add.insertAdjacentHTML( "BeforeBegin ", " <br> <input type=text name=pic id=Pic> ");
}
</script>
<input type= "text " name= "Pic " id= "Pic ">
<p id= "Add " onClick= "moreArea() "> <input type= 'button ' name= "More " value= '添加 ' > </p>
[解决办法]

<script type= "text/javascript ">
<!--
function Attachment(maxatts){
var attHTML = ' <!--Attachment--> <input type= "hidden " name= "attachprem " value= "0 " /> '
+ ' <table cellspacing= "0 " cellpadding= "0 "> <tbody> ' +
' <tr> <td style= "vertical-align:top; "> </td> '
+
' <td id= "att " style= "font-size:10pt; "> <div id= "ia "> <span class= "l " onclick= "javascript:initattachment(this); "> &nbsp;&nbsp;上传附件 </span> </div> '
+
' <div id= "aa " style= "display:none; "> <span class= "l " onclick= "javascript:addattachment(this); "> &nbsp;&nbsp;增加附件 </span> </div> </td> '
+
' </tr> </tbody> </table> ' + ' <!--/end Attachment--> ' ;
document.write(attHTML);
if(maxatts)
MAX_attachments = maxatts;
}


//////////Attachments Operations!
var VT_attachments = 0;
var MAX_attachments = 5;
var attach=null;
function initattachment(me)
{
var ia = me.parentNode;
var att = ia.parentNode;
if(att.id != 'att ')
return;

Ohidden(ia);
var aa = gObId( 'aa ');
Oshow(aa);
addattachment(aa);
}


function addattachment(me)
{
attach = document.createElement( 'div ');
var aa = gObId( 'aa ');
var att = aa.parentNode;
if(att.id != 'att ')
return;

switch(VT_attachments)
{
case 0:
fileid0();
break;
case 1:
fileid1();
break;
case 2:
fileid2();
break;
case 3:
fileid3();
break;
case 4:
fileid4();
break;
case 5:
fileid5();
break;
case 6:
fileid6();
break;
case 7:
fileid7();
break;
case 8:
fileid8(); break;
case 9:
fileid9();
break;
}

att.insertBefore(attach,aa);
VT_attachments ++ ;
if(VT_attachments > = MAX_attachments)
{
Ohidden(aa);
}
}

function fileid0()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid0 " type= "file " name= "fileid0 " width= "550 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}

function fileid1()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid1 " type= "file " name= "fileid1 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid2()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid2 " type= "file " name= "fileid2 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid3()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid3 " type= "file " name= "fileid3 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid4()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid4 " type= "file " name= "fileid4 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid5()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid5 " type= "file " name= "fileid5 " /> </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid6()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid6 " type= "file " name= "fileid6 " /> </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';


}
function fileid7()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid7 " type= "file " name= "fileid7 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid8()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid8 " type= "file " name= "fileid8 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function fileid9()
{
attach.innerHTML = '&nbsp;&nbsp; <span style= "font-size:10pt; "> &nbsp; <input id= "fileid9 " type= "file " name= "fileid9 " /> &nbsp; </span> <span class= "l " onclick= "javascript:delattachment(this); " style= "font-size:10pt; "> 删除 </span> ';
}
function delattachment(me)
{
var attach = me.parentNode;
var att = attach.parentNode;
if(att.id != 'att ')
return;
att.removeChild(attach);
VT_attachments -- ;
if(VT_attachments == 0)
{
Ohidden(gObId( 'aa '));
Oshow(gObId( 'ia '));
}else if(VT_attachments < MAX_attachments)
Oshow(gObId( 'aa '));


}

//Elements Operations
function Oshow(e)
{
e.style.display = " ";
}
function Ohidden(e)
{
e.style.display = "none ";
}
function gObId(id)
{
try{
return document.getElementById(id);
}
catch(e){
return null;
}
}
function isOshow(e)
{
return !(e.style.display == 'none ');
}


//-->
</script>


用法:

<script type= "text/javascript "> Attachment(10); </script>

热点排行