jqueryドロップダウンselectコントロール操作方法共有(jquery操作select)


JQuery取得とセットアップのオプション方法のまとめは以下の通りです。
コード:

$("#select_id").change(function(){//code...});   // Select ,
var checkText=$("#select_id").find("option:selected").text();  // Select Text
var checkValue=$("#select_id").val();  // Select Value
var checkIndex=$("#select_id ").get(0).selectedIndex;  // Select
var maxIndex=$("#select_id option:last").attr("index");  // Select
$("#select_id ").get(0).selectedIndex=1;  // Select 1
$("#select_id ").val(4);   // Select Value 4
$("#select_id option[text='jQuery']").attr("selected", true);   // Select Text jQuery
選択したテキストを取得します。

$("#ddlRegType").find("option:selected").text();
セレクトされたvalueを取得します。

$("#nowamagic").val();
選択した索引を取得します。

$("#nowamagic").get(0).selectedIndex;
セレクトを設定
jQuery SelectのOption項目を追加/削除:

$("#select_id").append("<option value='Value'>Text</option>");  // Select Option( )
$("#select_id").prepend("<option value='0'> </option>");  // Select Option( )
$("#select_id option:last").remove();  // Select Option( )
$("#select_id option[index='0']").remove();  // Select 0 Option( )
$("#select_id option[value='3']").remove();  // Select Value='3' Option
$("#select_id option[text='4']").remove();  // Select Text='4' Option
選択した索引を設定します。

//index
$("#nowamagic").get(0).selectedIndex=index;
セレクトで選択したvalueを設定します。

$("#nowamagic").attr("value","Normal");
$("#nowamagic").val("Normal");
$("#nowamagic").get(0).value = value;
select選択のテキストを設定:

var count=$("#nowamagicoption").length;
  for(var i=0;i<count;i++) 
     {           if($("#nowamagic").get(0).options[i].text == text) 
        { 
            $("#nowamagic").get(0).options[i].selected = true; 

            break; 
        } 
    }
クリアセット:

$("#nowamagic").empty();