我有一个选择列表,您可以在其中选择1到12的数字。根据选择的数字,我希望相同数量的输入框可以用于$ _POST。我无法获得onchange事件来触发任何相关的Java?
编辑:我真的只是摸索着我现在得到的任何东西:
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.11.0.min.js"></script>
<script>
function getNPlayers(element) {
var element = document.createElement('input');
element.appendChild(document.createTextNode
('some text for testing'));
}
</script>
</head>
<body>
<h1>My Web Page</h1>
<table>
<tr>
<td><select id="NPlayers" sel.onchange="getNPlayers(this)">
<option value="" disabled="disabled" selected="selected">Number of players</option>
<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>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select></td>
<tr id="other_fields" style="display:none">
<td>
Players:<br>
<input type="tex" value=""/><br>
<input type="tex" value=""/><br>
<input type="tex" value=""/><br>
<input type="tex" value=""/><br>
</td>
</tr>
</tr>
</tr>
</table>
</body>
</html>
答案 0 :(得分:0)
<html>
<head>
<title>Dynamic Textbox</title>
<script>
function generate(total,id){
var drpDown = document.getElementById(id);
for(i=0;i<total;i++){
var child = document.createElement("input");
child.id = "test"+i;
child.name = "test"+i;
drpDown.parentNode.insertBefore(child,drpDown);
}
}
</script>
</head>
<body>
<select id='test' onchange='generate(this.value,"test")'>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
</select>
</body>
</html>