我的下拉框由style sheet (xsl文件)生成如下:
<select name="SLk1" id="SLk1" size="1"><option value="OBW">That Begins With</option><option value="OOS">That Contains</option><option value="OEM" selected="true">That Equals</option></select>但是这个页面load时有一种情况是需要将“That Begins With”和“That Contains”给去掉。我用的方法如下:
var sel = document.getElementById('SLk1');
...
sel.removeChild(sel.options[0]); 这样的话SLk1下拉框的内容长度就比正常请况短了,刚好能容纳“That Equals”。
请问如何使得下拉框的内容长度和原来一样,就是一直是能容纳原来的3个内容,即使出现只有“That Equals”的情况。
谢谢!
<select name="SLk1" id="SLk1" size="1"><option value="OBW">That Begins With</option><option value="OOS">That Contains</option><option value="OEM" selected="true">That Equals</option></select>但是这个页面load时有一种情况是需要将“That Begins With”和“That Contains”给去掉。我用的方法如下:
var sel = document.getElementById('SLk1');
...
sel.removeChild(sel.options[0]); 这样的话SLk1下拉框的内容长度就比正常请况短了,刚好能容纳“That Equals”。
请问如何使得下拉框的内容长度和原来一样,就是一直是能容纳原来的3个内容,即使出现只有“That Equals”的情况。
谢谢!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function test(){
var sel = document.getElementById('SLk1');
if(sel.options[0])
sel.removeChild(sel.options[0]);
}
</script>
</head>
<body>
<select name="SLk1" id="SLk1" size="1" style="width:200px;" >
<option value="OBW">That Begins With</option>
<option value="OOS">That Contains</option>
<option value="OEM" selected="selected">That Equals</option>
</select>
<br />
<input type="button" onclick="test()" value="测试" />
</body>
</html>