日期:2014-05-16 浏览次数:20813 次
<html>
<head>
</head>
<body id="body_note">
<form name="myform" method="post" action="ss_kuku.asp">
<input type="button" value="增加文本框" onClick="InsertNode();" />
<input type="button" value="删除文本框" onClick="DelNode()" /><p></p>
<input type="submit" name="cufa"></form>
</body>
</html>
<script language="javascript" type="text/javascript">
var obj = document.getElementById("body_note"); //根目录
var InputNum = 1;
function InsertNode ()
{
if (InputNum < 1)
{
InputNum = 1;
}
if (InputNum <= 11)
{
//创建div
nDiv = document.createElement("div");
obj.appendChild(nDiv);
//创建文本框
nInput = document.createElement("input");
InputID = "lr" + InputNum;
nInput.setAttribute("id", InputID);
nInput.setAttribute("value", InputID);
obj.appendChild(nInput);
bgColor = (InputNum%2 == 1) ? "#EFEFEF": "#CCCCCC";
document.getElementById(InputID).style.backgroundColor = bgColor;
InputNum++;
}
else
{
alert("只能创建十个文本框!");
}
}
function DelNode()
{
InputNum--;
if (InputNum > 0)
{
delInput = document.getElementById("input" + InputNum);
obj.removeChild(delInput);
}
else
{
alert("没有可删除的文本框了!");
}
}
</script>