js总结:增加和减少文本框

<head>
<script>
var count = 0;

function add()
{
if(count<3)
{
count++;
var x= document.createElement("input");
x.setAttribute("type","text");
x.setAttribute("name","gjdw"+count);
x.setAttribute("id","gjdw"+count);
var td = document.getElementById("gjdw0");
td.appendChild(x);
}
}

function del()
{
if(count>=1)
{
var td = document.getElementById("gjdw"+count);
td.parentNode.removeChild(td);
count--;
}
}
</script>
</head>

<body>
<td colspan="4" id="gjdw0">
<%
if(user.getGjdw()==null)
{
user.setGjdw("");
}
%>
<input type="button" value="增加" onclick="add()"/>
<input type="button" value="减少" onclick="del()"/>
</td>
</body>

posted @ 2018-04-11 21:30  Felix_9190  阅读(203)  评论(0编辑  收藏  举报