## 這兩種方式取不到索引值
```
$('#select_id').find('option:selected').selectedIndex;
$('#select_id').find('option:selected').attr('selectedIndex');
```
5.設置select 選中的索引:
```
$("#select_id").get(0).selectedIndex=index;//index為索引值
```
```
3. $("#select_id option[text='jQuery']").attr("selected", true); //設置Select的Text值為jQuery的項選中 ,我這里沒用
var cc1 = $(".formc select[@name='country'] option[@selected]").text(); //得到下拉菜單的選中項的文本(注意中間有空格)
var cc2 = $('.formc select[@name="country"]').val(); //得到下拉菜單的選中項的值
var cc3 = $('.formc select[@name="country"]').attr("id"); //得到下拉菜單的選中項的ID屬性值
```
## jQuery添加/刪除Select的Option項:
```
4. $("#select_id option[index='0']").remove(); //刪除Select中索引值為0的Option(第一個) //我這里不能用
5. $("#select_id option[text='4']").remove(); //刪除Select中Text='4'的Option //我這里不能用
```
## 不能用的
9.刪除select中值為value的項 (我這里不能用)
```
var count = $("#select_id").size();
for(var i=0;i<count;i++)
{
if($("#select_id").get(0).options[i].value == 'value')
{
$("#select_id").get(0).remove(i);
break;
}
}
```
7.設置select 選中的text:
1> //我不能用
```
var count=$("#select_id").get(0).options.length;
for(var i=0;i<count;i++)
{
if($("#select_id").get(0).options.text == text)
{
$("#select_id").get(0).options.selected = true;
break;
}
}
```
6.設置select 選中的value:
```
$("#select_id").attr("value","Normal"); //我不能用
$("#select_id").get(0).value = "Normal"; //我不能用
```
需要注意的是,這里的代碼好多是針對jquery 1.32以前的版本(以后的版本已經不支持@),所以替換為空測試下即可。
```
//遍歷option和添加、移除option
function changeShipMethod(shipping){
var len = $("select[@name=ISHIPTYPE] option").length
if(shipping.value != "CA"){
$("select[@name=ISHIPTYPE] option").each(function(){
if($(this).val() == 111){
$(this).remove();
}
});
}else{
$("<option value='111'>UPS Ground</option>").appendTo($("select[@name=ISHIPTYPE]"));
}
}
```