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

50分求助!如何用javascript自动生成文本框?
想做这样的效果:
在页面的一个文本框中输入数字(比如3)时,通过javascript在前台生成文本框,输入的数字是多少就生成几个,名称分别为
<input   name= 'text1 '>
<input   name= 'text2 '>
<input   name= 'text3 '>
。。
请问如何实现?菜鸟谢谢大家

------解决方案--------------------
<input name= "numText " > <input name= "button1 " type= "button " value= "确定 " onclick=show()>
<div id= "div1 "> &nbsp;
</div>
<script language=javascript>
function show()
{
var num=parseInt(document.getElementById( "numText ").value)
if(isNaN(num))
{
alert( '错误 ')
return
}
var temp=new Array()
for(var i=0;i <num;i++)
{
temp[i]= " <input name= 'text "+(parseInt(i)+parseInt(1))+ " '> "
}
document.getElementById( "div1 ").innerHTML=temp.join( " ");
}
</script>
------解决方案--------------------
<html>
<title> read xml </title>
<script language=javascript>
function aa()
{
var str1= " ";
for(i=0;i <form1.int1.value;i++)
{
str1=str1+ " <input name= 'text "+i+ " '> ";
}
window.span1.innerHTML=str1;
}

</script>
<body>
<form name= "form1 " ID= "Form1 ">
<span id= "span1 "> </span>
<input type= "text " name= "int1 " ID= "Text1 ">
<input type= "button " name= "b1 " value= "生成 " onclick= "aa(); " ID= "Button1 ">
</form>
</body>
</html>
------解决方案--------------------
<html>
<title> read xml </title>
<script language=javascript>
function aa()
{
var str1= " ";
for(i=0;i <document.getElementById( "int1 ").value;i++)
{
str1=str1+ " <input name= 'text "+i+ " '> ";
}
window.span1.innerHTML=str1;
}

</script>
<body>
<span id= "span1 "> </span>
<input type= "text " name= "int1 " ID= "Text1 ">
<input type= "button " name= "b1 " value= "生成 " onclick= "aa(); " ID= "Button1 ">
</body>
</html>
------解决方案--------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 无标题文档 </title>
</head>

<body>
<p>
<script language= "javascript ">
function test( args ){
var tempStr = " ";
for( var i=0 ; i <args ; i++ ){
//alert(i);
tempStr = tempStr + " <input name= 'text "+i+ " ' id= 'text "+i+ " ' type=text /> <br> ";
}
document.getElementById( "outtest ").innerHTML = tempStr;