根据你个人需求了
可以控制隐:$("").style.visibility = "hidden"
也可以生成
createElement("");
appendChild();
解决方案 »
- 怎样看FireBug的网络面板的数据啊?
- 大数据处理方式
- Marquee
- 出去做项目时看到别人这个效果,不知道是怎么做的.
- 急救:window.open()第一个参数url中含有'#',页面不能正常打开怎么办?在线等。
- <select>中以列表的形式显示数据,如果做像<img alt="">中提示信息将所选择的行的数据提示出来?
- 圆砣学JS,,,谢谢大家呀...
- 高分求javascript完整对象手册,谢谢
- 我的js提交为什么在IE6下可以,在IE5下不行?改如何修改?
- js checkbox 勾选
- javascript一个下拉列表的数据写入另一个下拉列表
- 脚本里如何修改<a>dd</a>标签中"dd"为"ee"?
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
var CreateText=function(){
var module=document.getElementById("textmoudle");
var a = document.createElement("input");
a.id="num"
a.type = "text";
a.value = "";
module.appendChild(a);
};
var DeleteText=function(){
var module=document.getElementById("textmoudle");
var texts=document.getElementsByTagName("num");
module.removeChild(document.getElementsByTagName("num")[0]);
};
</script>
<BODY>
<input type="button" value="增加" onclick="CreateText()"/>
<input type="button" value="删除" onclick="DeleteText()"/>
<hr/>
<div id="textmoudle">
<input id="num" type="text" value=""/>
</div>
</BODY>
</HTML>
--------------------
没有测试!请测试下
http://blog.chinaunix.net/u1/57965/showart_688399.html
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
var CreateText=function(){
var module=document.getElementById("textmoudle");
var a = document.createElement("input");
a.id="num"
a.type = "text";
a.value = "";
module.appendChild(a);
};
var DeleteText=function(){
var module=document.getElementById("textmoudle");
var texts=document.getElementsByName("num");
//alert(texts.length);
module.removeChild(document.getElementsByName("num")[0]);
};
</script>
<BODY>
<input type="button" value="增加" onclick="CreateText()"/>
<input type="button" value="删除" onclick="DeleteText()"/>
<hr/>
<div id="textmoudle">
<input id="num" type="text" value=""/>
<input id="num" type="text" value=""/>
</div>
</BODY>
</HTML>
====================
不好意思,我测试了,有点问题!这个是修改了下!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
<head>
</head>
<script>
var create_element = function()
{
var _input = document.createElement("input");
var _button = document.createElement("input");
var _del_button = document.createElement("input");
_button.setAttribute("type","button");
_button.setAttribute("value",'增加');
_del_button.setAttribute("type","button");
_del_button.setAttribute("value","删除");
document.body.appendChild(_input);
document.body.appendChild(_button);
document.body.appendChild(_del_button);
}
var add_input = function()
{
var _input = document.createElement("input");
_input.setAttribute("type","text");
document.body.appendChild(_input);
}
var remove_input = function()
{
document.body.removeChild(document.body.lastChild);
}
window.onload = function()
{
create_element();
if(document.all)
{
document.body.lastChild.previousSibling.attachEvent("onclick",add_input);
document.body.lastChild.attachEvent("onclick",remove_input);
}
else
{
document.body.lastChild.previousSibling.addEventListener("click",add_input,false);
document.body.lastChild.addEventListener("click",remove_input,false);
}
}
</script>
<body></body>
</html>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<script type="text/javascript">
var CreateText=function(){
if(document.getElementsByName("num").length +1 >5)
{
alert("已经5个了,不能继续添加!");
return ;
}
var module=document.getElementById("textmoudle");
var a = document.createElement("input");
a.id="num"
a.type = "text";
a.value = "";
module.appendChild(a);
};
var DeleteText=function(){
if(document.getElementsByName("num").length ==1)
{
alert("已经剩下最后一个了,不要再删除了!谢谢!");
return ;
}
var module=document.getElementById("textmoudle");
var texts=document.getElementsByName("num");
//alert(texts.length);
module.removeChild(document.getElementsByName("num")[0]);
};
</script>
<BODY>
<input type="button" value="增加" onclick="CreateText()"/>
<input type="button" value="删除" onclick="DeleteText()"/>
<hr/>
<div id="textmoudle">
</div>
</BODY>
</HTML>
<script type="text/javascript">
var p=1;
function pga(){p=p;return p;}
function Up_page(){if(p<=1)p=1;else p=p-1;return p;}
function Down_page(){if(p<5)p=p+1;return p;}
function bbb(aa)
{
var obj=document.getElementById("ccc");
var html="";
for(i=1;i<=aa;i++)
{
html+="<input type='textbox' name=user+'i+1'/>"
}
obj.innerHTML=html;
}
</script>
</head>
<body>
<div id="ccc"><input type='textbox' name=user1/></div>
<input type="button" value="添加" onclick="bbb(Down_page());"/>
<input type="button" value="删除" onclick="bbb(Up_page());"/>
</body>
</html>
有一组输入框(三个TextBox,两个DropdownList),最少显示一组.通过增加,删除按钮来显示一组至五组输入框.最多显示五组.
还是<div visible="false">都没有反应。请问是怎么回事?》
//是style.visibility,不是div.visible
div.style.visibility="visible";
div.style.visibility="hidden";div.style.display="none"//隐藏
div.style.display="block"//显示建议使用style.display,使用visibility的话会占位置
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<div id="div_cjr_1">
</div>
<div id="div_cjr_2">
</div>
<div id="div_cjr_3">
</div>
<div id="div_cjr_4">
</div>
<div id="div_cjr_5">
</div>
window.onload=initForm;
window.onunload=function() {};function initForm()
{
document.getElementById("Select_P").selectedIndex=0;
document.getElementById("Select_P").onchange=changnum;
}function changnum()
{
var newnum=document.getElementById("Select_P");
for(var i=0;i<newnum;i++)
{
div_cjr_[i].style.display="block";//显示
}
}
选择列表怎么没反应呢??
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option></select>
<div id="div_cjr_1">1
</div>
<div id="div_cjr_2">2
</div>
<div id="div_cjr_3">3
</div>
<div id="div_cjr_4">4
</div>
<div id="div_cjr_5">5
</div> <script>
window.onload=initForm;
window.onunload=function() {};function initForm()
{
document.getElementById("Select_P").selectedIndex=0;
for(i=2;i<=5;i++)
{
document.getElementById("div_cjr_"+i).style.display="none";//隐藏2-5,因为你上面设置了只显示1个div
}
document.getElementById("Select_P").onchange=changnum;
}function changnum()
{
var newnum=parseInt(document.getElementById("Select_P").value);
var i,j;
for(i=1;i<=newnum;i++)
{
document.getElementById("div_cjr_"+i).style.display="block";//显示
}
for(j=i;i<=5;i++)
{
document.getElementById("div_cjr_"+j).style.display="none";//隐藏
}
}
</script>
显示style='display:block';显示默认是显示