是这样吧<!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=utf-8" />
<title>无标题文档</title>
</head><body>
<input type="text" onblur="fun(this.value)" /><br/>
<script type="text/javascript">
function fun(v)
{
var l = parseInt(v,10);
for(var i=0;i<l;i++)
{
var ipt = document.createElement("input");
ipt.type = "text";
document.body.appendChild(ipt);
}
}
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<input type="text" onblur="fun(this.value)" /><br/>
<script type="text/javascript">
function fun(v)
{
var l = parseInt(v,10);
for(var i=0;i<l;i++)
{
var ipt = document.createElement("input");
ipt.type = "text";
document.body.appendChild(ipt);
}
}
</script>
</body>
</html>
你这个是把节点添加到body后面了
<!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=utf-8" />
<title>无标题文档</title>
</head><body>
<form>
<input type="text" onblur="fun(this.value)" /><br/>
<script type="text/javascript">
function fun(v)
{
var l = parseInt(v,10);
for(var i=0;i<l;i++)
{
var ipt = document.createElement("input");
ipt.type = "text";
this.parentNode.appendChild(ipt);
}
}
</script>
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>create New Form</title>
<script type="text/javascript">
function createNew(){
var form1 = document.getElementsByName("form1")[0];
var icount = document.getElementsByName("count")[0];
var count = icount.getAttribute("value");
var div1 = document.getElementById("div1");
var i = 0;
var newInput = document.createElement("input"); newInput.type = "text";
newInput.name= "username";
form1.appendChild(newInput);
}
</script>
</head>
<body onload="">
<form name="form1">
输入有多少到题:<input type="text" name="count" onblur="createNew()"/>
<br/>
<div id = "div1">
在这个前面输出:<input type = "text" name = "after" />
<br/>
<input type="submit"/>
</form>
</body>
</html>
<html><head><title>create New Form</title>
<script type="text/javascript">
function createNew(obj)
{
for(var i=0;i<obj.value;i++)
{ var newE = document.createElement("div")
var input = document.createElement("input")
input.type="text"
newE.appendChild(input);
var oldE=obj.parentNode.nextSibling
document.forms[0].insertBefore(newE,oldE)
}}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"></head><body onload=""> <form name="form1">
<div>输入有多少到题:<input type="text" name="count" onblur="createNew(this)"/></div>
<div><input type="submit"/></div>
</form></body></html>
var oldE2=document.getElementById("three") ;oldE1与oldE2有什么区别啊?
var oldE=obj.parentNode.nextSibling 主要是找提交按钮所在的div,换成标识ID的写法应该可以满足你说的要求
但是为什么呢?var oldE=obj.parentNode.nextSibling这句话找到的不应该是name = count那个节点吗 ?
var oldE=obj.parentNode.nextSibling找到的是 <div><input type="submit"/></div>当中的div元素
你alert(oldE.innerHTML)看看