日期:2014-05-16 浏览次数:20385 次
<script> function AddSelect(){ var selectbox=document.getElementById('sel'); var newOption=new Option('c','c'); selectbox.add(newOption,undefined); selectbox.insertBefore(newOption,selectbox.options[0]); selectbox.selectedIndex=0; } </script> <select id="sel"> <option value='a'>a</option> <option value='b'>b</option> </select> <input type="button" value="Add" onclick="AddSelect()">
------解决方案--------------------
<script type="text/javascript">
function add(){
var a=new Option("4","4");
var se=document.getElementById("test");
var f=se.firstChild;
se.insertBefore(a,f);
se.selectedIndex=0;
}
</script>
</head>
<body>
<select id="test">
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<input type="button" onclick="add()" value="add">
------解决方案--------------------
两者都可以!不错