87,907
社区成员
发帖
与我相关
我的任务
分享
<select id="s1" size="4" >
<option value="key0" >text0</option>
<option value="key1" >text1</option>
<option value="key2" >text2</option>
<option value="key3" >text3</option>
<option value="key4" >text4</option>
<option value="key5" >text5</option>
</select>
<!doctype html >
<html>
<head>
<title> new document </title>
<script type="text/javascript">
function hide(n){
var sel = document.getElementById("s1");
var span = document.createElement("span");
span.style.display = "none";
span.id = "span" + n;
sel.insertBefore(span, sel.options[n]);
span.appendChild(sel.options[n]);
};
function show(n){
var sel = document.getElementById("s1");
span = document.getElementById("span"+n);
if(span){
sel.insertBefore(span.getElementsByTagName("option")[0], sel.options[n]);
sel.removeChild(span);
}
};
</script>
</head>
<body>
<select id="s1" size="4" >
<option value="key0" >text0</option>
<option value="key1" >text1</option>
<option value="key2" >text2</option>
<option value="key3" >text3</option>
<option value="key4" >text4</option>
<option value="key5" >text5</option>
</select>
<input type="button" value="隐藏" onclick='hide(2)' />
<input type="button" value="显示" onclick='show(2)' />
</body>
</html>