一个表单中,有很一个文本框,要求是在这个文本框右侧有一个增加、删除的按钮点增加后,这个文本框后面会增加一个新的文本框,点一次加一次点删除后,会删除这个文本框请问这个js怎么实现呢?
解决方案 »
- js怎么设置div层左边距 及与顶部边距
- coolite(extnet)在gridpanel里面的cloumn中,很难选择下拉框.。。。。
- checkbox选中问题
- 求自动发帖程序的思路
- 如何让弹出窗口处于showmodule状态?使得不能点击父窗体
- 如何将点击文字链接以后弹出的一张图片的页面,使弹出的web页面于图片一样大
- return this.replace(/(^\s*) |(\s*$)/g, ""); ,解释一下这个的意思
- IDEA中 编写javascript,经过变量赋值后 没有代码提示了
- 求帮助!如何实现多个div同时拖动进多个div中?
- js按需加载大文本文件
- 如何用JS得到当前系统日期是星期几
- 高手帮一下,判断控件为空
用jquery的话很好操作的。
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<META http-equiv="Content-Style-Type" content="text/css"> <script language="javascript">
function addInput(){
var div=document.getElementById("inputDiv");
var input=document.createElement("input");
div.appendChild(input);
}
function decInput(){
var div=document.getElementById("inputDiv");
if(div.childNodes[0]!=null)
div.removeChild(div.childNodes[0]);
}
window.onload=function(){
}
</script>
</head>
<body>
<div id=inputDiv></div><div><input type=button onclick=addInput() value="+"></inpit><input type=button onclick=decInput() value="-" ></inpit></div> </body>
</html>
<input id="addNext" /> <a id="addNext" onclick="AddNextFn();" href="javascript:;" name="addNext">添加</a>
<table width="200" border="0" id="addNextTable">
</table>
<script language="javascript" type="text/javascript">
function AddNextFn()
{
var table = document.getElementById('addNextTable');
var nRow = table .insertRow();
nRow .insertCell().innerHTML = "<input name='txt' type='text'><input type=button value='删除' onclick='delText(this.parentElement.parentElement.rowIndex)'>";
}
function delText(index)
{
document.getElementById('addNextTable').deleteRow(index);
}
</script>
</body></html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<META http-equiv="Content-Style-Type" content="text/css">
<script language="javascript">
function addInput(){
var div=document.getElementById("inputDiv");
var input=document.createElement("input");
div.appendChild(input);
}
function decInput(){
var div=document.getElementById("inputDiv");
if(div.childNodes[0]!=null&&div.childNodes.length>1)
div.removeChild(div.childNodes[0]);
}
window.onload=function(){
}
</script>
</head>
<body>
<div id="inputDiv"><input type=text /></div>
<div ><input type="button" onclick="addInput()" value="+"></inpit><input type="button" onclick="decInput()" value="-"></inpit></div>
</body>
</html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<META http-equiv="Content-Style-Type" content="text/css">
<script language="javascript">
function addInput(){
var div=document.getElementById("inputDiv");
var input=document.createElement("input");
div.appendChild(input);
}
function decInput(){
var div=document.getElementById("inputDiv");
var nodeLen=div.childNodes.length;
if(div.childNodes[nodeLen-1]!=null&&nodeLen>4)
div.removeChild(div.childNodes[nodeLen-1]);
}
window.onload=function(){
}
</script>
</head>
<body>
<div id="inputDiv"><input type="text" /><input type="button" onclick="addInput()" value="+" ></inpit><input type="button" onclick="decInput()" value="-" ></inpit></div>
<div></div>
</body>
</html>