<html>
<head>
<script language="javascript">
function doblur(inputobj)
{
var count=inputobj.value;
var count2=parseInt(count);
for(var i=0;i<count2;i++)
{
table = document.all["tb"];
var Row1=table.insertRow(table.rows.length-1);
j = table.rows.length ;
var Rows=table.rows;
var Cells=Row1.cells;
var Cell1=Rows(Row1.rowIndex).insertCell(Cells.length);
Cell1.align="center";
Cell1.innerHTML="<input type='text' name='textfield' />";
}
}
</script
</head>
<form name=form1 action="" method="">
人数:<input type="text" name="count" onblur="javascript:doblur(this)">
<input type="button" onclick="doblur()">
<table width="662" border="1" id="tb"> </table>
</form>
</html>
<head>
<script language="javascript">
function doblur(inputobj)
{
var count=inputobj.value;
var count2=parseInt(count);
for(var i=0;i<count2;i++)
{
table = document.all["tb"];
var Row1=table.insertRow(table.rows.length-1);
j = table.rows.length ;
var Rows=table.rows;
var Cells=Row1.cells;
var Cell1=Rows(Row1.rowIndex).insertCell(Cells.length);
Cell1.align="center";
Cell1.innerHTML="<input type='text' name='textfield' />";
}
}
</script
</head>
<form name=form1 action="" method="">
人数:<input type="text" name="count" onblur="javascript:doblur(this)">
<input type="button" onclick="doblur()">
<table width="662" border="1" id="tb"> </table>
</form>
</html>
只实现了输入的是几,下面就出现几个输入框。再次输入人数时没有清空,也就是说,你输入5,人数输入框失去焦点的时候,下面会出现5个输入框。但是如果你再改成4,下面不是变成4个,而是出现9个。因为我是仿照别的javascript代码改的,我不懂,所以我不会做。
应该是失去焦点时清空掉然后再根据输入的数字。。
还有应该检验输入的不是数字的话给予提示
function showText(obj){
var div=document.getElementById("div");
var num=obj.value;
if(/^\d+$/.test(num)){
num=parseInt(num);
var text="<input type=text id=text2 name=text><br>";
div.innerHTML=new Array(num+1).join(text);//新偷的招,有变值的话用循环
}else{
alert("Input error!");
obj.select();
}
}
</script>
<input type=text name=text1 onblur="showText(this)">
<div id=div></div>
<head> </head>
<script language=javascript>
function showText(obj){
var div=document.getElementById("div");
var num=obj.value;
if(/^\d+$/.test(num)){
num=parseInt(num);
var text="<table> \
<tr>\
<td>123</td>\
</tr>\
</table>";
div.innerHTML=new Array(num+1).join(text);//新偷的招,有变值的话用循环
}else{
alert("Input error!");
obj.select();
}
}
</script>
<input type=text name=text1 onblur="showText(this)">
<div id=div></div>
</html>
<tr>\
<td>123</td>\
</tr>\
</table>"; 这样写对不对
text 的内容很多,需要好几行。
我这样写不能实现。。
+"<tr>"
+"<td>123</td>"
+"</tr>"
+"</table>";