select name="sdfsdf" id="id2">
<option value="apple1val">apple1</option>
<option value="apple2val">apple2</option>
</select>
<script type="text/javascript">
$(document).ready(function(){
var obj=document.getElementById("id2") // 取得select对象
obj.selectedIndex;//表示当前选中项的索引
obj.options[obj.selectedIndex]=null;//删除当前选中项
//也可以这样删除
obj.remove(obj.selectedIndex);
obj.options[obj.options.length] = new Option("你好","hello"); //添加一项新值,第一个参数为text,第二个参数为value
//也可以这样添加option项
var opt=new Option();
opt.value="value1";
opt.text="text1";
obj.add(opt);
obj.options[obj.selectedIndex].text;//取得当前选择项的text;
obj.options[obj.selectedIndex].value;//取得当前选中项的value;
//也可以这样去,和上面的效果一样,但是不能使用obj.text
obj.value;
obj.options[obj.selectedIndex]= new Option("你好","hello");//修改当前选中项;
obj.options.length;//获取此select对象包含多少option项;
//删除所有option项
for(var i = obj.options.length-1;i>-1;i--) {
objSelect.options[i] = null;
}
obj.options.length = 0;//这样也可以删除所有元素
obj.options[i].selected = true//设置某一项为当前选中项
});
</script>
<option value="apple1val">apple1</option>
<option value="apple2val">apple2</option>
</select>
<script type="text/javascript">
$(document).ready(function(){
var obj=document.getElementById("id2") // 取得select对象
obj.selectedIndex;//表示当前选中项的索引
obj.options[obj.selectedIndex]=null;//删除当前选中项
//也可以这样删除
obj.remove(obj.selectedIndex);
obj.options[obj.options.length] = new Option("你好","hello"); //添加一项新值,第一个参数为text,第二个参数为value
//也可以这样添加option项
var opt=new Option();
opt.value="value1";
opt.text="text1";
obj.add(opt);
obj.options[obj.selectedIndex].text;//取得当前选择项的text;
obj.options[obj.selectedIndex].value;//取得当前选中项的value;
//也可以这样去,和上面的效果一样,但是不能使用obj.text
obj.value;
obj.options[obj.selectedIndex]= new Option("你好","hello");//修改当前选中项;
obj.options.length;//获取此select对象包含多少option项;
//删除所有option项
for(var i = obj.options.length-1;i>-1;i--) {
objSelect.options[i] = null;
}
obj.options.length = 0;//这样也可以删除所有元素
obj.options[i].selected = true//设置某一项为当前选中项
});
</script>