<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#slct').change(function () {
var value = $(this).val(); var toAppend = '';
if (value == 1) {
toAppend = "<input type='textbox' >"; $("#container").html(toAppend); return;
}
if (value == 2) {
toAppend = "<input type='textbox' > <input type='textbox' >"; $("#container").html(toAppend); return;
}
if (value = 3) {
toAppend = "<input type='textbox' > <input type='textbox' > <input type='textbox' >"; $("#container").html(toAppend); return;
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<select id="slct">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
</select>
<div id="container"></div>
</div>
</form>
</body>
</html>
如果 jquery 对您不起作用,请尝试以下代码:
function change() {
var select = document.getElementById("slct");
var divv = document.getElementById("container");
var value = select.value;
if (value == 1) {
toAppend = "<input type='textbox' >"; divv.innerHTML=toAppend; return;
}
if (value == 2) {
toAppend = "<input type='textbox' > <input type='textbox' >";divv.innerHTML = toAppend; return;
}
if (value = 3) {
toAppend = "<input type='textbox' > <input type='textbox' > <input type='textbox' >";divv.innerHTML = toAppend; return;
}
}
<select id="slct" onchange="change();">
<option value="1"> 1 </option>
<option value="2"> 2 </option>
<option value="3"> 3 </option>
</select>
<div id="container"></div>