台灣最大程式設計社群網站
線上人數
858
 
會員總數:245619
討論主題:189317
歡迎您免費加入會員
討論區列表 >> 專欄文章 >> 動態新增輸入欄位
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
動態新增輸入欄位
價值 : 0 QP  點閱數:651 回應數:0
樓主

站務人員 站長
門外漢
0 1580
542 9
發送站內信

捐贈 VP 給 站務人員
試試下列網頁程式ㄅ!如果可以的話!我建議利用 <TABLE> 來處理文字方塊排版,這樣子加項和減項的功能比較好作!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>動態新增項目</title>
</head>

<body>
<form name="formInput">
<input type="button" onclick="javascript:formInput.test.value=formInput.innerHTML;" value="檢視原始碼">
<textarea name="test" cols="80" rows="8"></textarea>

文字方塊總數
<input type="text" name="counter" value="0" size="5">
<input type="button" onclick="javascript:addone();" value="加項">
<hr>
</form>
</body>

</html>
<script language="javascript">
function addone(){
var intCnt, strHTML, strName;

intCnt = eval(formInput.counter.value);
intCnt = intCnt + 1;
strHTML = 'INPUT BOX #' + intCnt;
strHTML = strHTML + '<input type="text" name="txt' + intCnt + '" value="">';
formInput.insertAdjacentHTML("BeforeEnd", strHTML);
formInput.counter.value = intCnt;
}
</script>

=========================================================================

回應者: nbhero

給一段完整的代碼,我以前做的:
<HTML>
<HEAD>
<meta http-equiv="Content-Language" content="zh-cn">
<META NAME="GENERATOR" Content="Microsoft FrontPage 5.0">

<SCRIPT LANGUAGE=vbscript>
<!--
function button1_onclick()
if form1.countinput.value>50 then
if msgbox("您的下載地址數已超過50個,還要繼續添加嗎?",vbyesno,"用心軟體") =vbyes then
inputarea.innerHTML=inputarea.innerHTML +"下載"+form1.countinput.value+":<INPUT type='text' id=link"+form1.countinput.value+" name=link"+form1.countinput.value+" class=wly>"
form1.countinput.value =form1.countinput.value+1
end if
else
inputarea.innerHTML=inputarea.innerHTML +"下載"+form1.countinput.value+":<INPUT type='text' id=link"+form1.countinput.value+" name=link"+form1.countinput.value+" class=wly>"
form1.countinput.value =form1.countinput.value+1
end if
end function

function button2_onclick()
if form1.addlink.value="" then
msgbox "請填入一個數位!!!",vbokonly,"用心軟體"
exit function
end if
if form1.countinput.value*1+form1.addlink.value*1>50 then
if msgbox("您的下載地址數已超過50個,還要繼續添加嗎?",vbyesno,"用心軟體") =vbyes then
for i=0 to form1.addlink.value-1
inputarea.innerHTML=inputarea.innerHTML +"下載"+form1.countinput.value+":<INPUT type='text' id=link"+form1.countinput.value+" name=link"+form1.countinput.value+" class=wly>"
form1.countinput.value =form1.countinput.value+1
form1.addlink.value=5
next
end if
else
for i=0 to form1.addlink.value-1
inputarea.innerHTML=inputarea.innerHTML +"下載"+form1.countinput.value+":<INPUT type='text' id=link"+form1.countinput.value+" name=link"+form1.countinput.value+" class=wly>"
form1.countinput.value =form1.countinput.value+1
form1.addlink.value=5
next
end if
end function

function button3_onclick()
if form1.addlink.value="" then
msgbox "請填入一個數位!!!",vbokonly,"用心軟體"
exit function
end if
if form1.countinput.value*1-form1.addlink.value*1<2 then
msgbox "減少的下載地址數少於或等於現有的下載地址數!",vbokonly,"用心軟體"
exit function
else
elcount=form1.countinput.value*1-form1.addlink.value*1-2
form1.countinput.value=1
for i=0 to elcount
if i=0 then inputarea.innerhtml=""
inputarea.innerhtml=inputarea.innerhtml+"下載"+form1.countinput.value+":<INPUT type='text' id=link"+form1.countinput.value+" name=link"+form1.countinput.value+" class=wly>"
form1.countinput.value =form1.countinput.value+1
form1.addlink.value=5
next
end if
end function
-->
</SCRIPT>
</HEAD>
<BODY>
<%
dim linkid()
redim linkid(request("countinput")-1)
for each thing in request.form
if left(thing,4)="link" then
linkid(right(thing,len(thing)-4))= "<div>連接"+right(thing,len(thing)-4)+":"+request("link"+right(thing,len(thing)-4))+"</div>"
end if
next
for i=1 to ubound(linkid)
response.write linkid(i)
next
%>
<P><form id=form1 method=post action=me.asp>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0 height="141" style="BORDER-COLLAPSE: collapse" bordercolor="#111111">

<TR>
<TD colspan=2>下載地址:<INPUT id=button1 type=button value=增加一個連接 name=button1 class=wly>  指定連接:<input name="addlink" value='5' size="5" class=wly ><INPUT id=button2 type=button value=增加 name=button2 class=wly><INPUT id=button3 type=button value=減少 name=button3 class=wly></TD>
</TR>

<TR>
<td width=10> </td>
<TD id=inputarea height="90">
連接1:<input name="link1" class=wly
>
連接2:<input name="link2" class=wly >
連接3:<input name="link3" class=wly >
連接4:<input name="link4" class=wly
>
連接5:<input name="link5" class=wly ></TD>
</TR>
<TR>
<TD height="41" colspan=2><INPUT id=countinput type=hidden value=6 name=countinput>
<INPUT type="submit" value=" 提交 " id=submit1 name=submit1 class=wly></TD>
</TR>
</TABLE>

</form></P>
</BODY>
</HTML>


本篇文章發表於2002-06-12 00:00
目前尚無任何回覆
   

回覆
如要回應,請先登入.