JS部分:
<script type="text/javascript"> function CreateInput(){ document.getElementById('addinput').innerHTML = ""; num = document.getElementById('select').value; for(i=0;i<num;i++){ inform = document.getElementById('addinput'); newinput = document.createElement('input'); newinput.type = "text"; newinput.name = "text" + i; newinput.id = "text" + i; inform.appendChild(newinput); addBr = document.createElement('<br />'); inform.appendChild(addBr); } } </script>
HTML部分:
<form id="form1" name="form1" method="post" action=""> <select name="select" id="select" onchange="CreateInput()"> <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> <br /> <span id="addinput"></span> </form>