JQuery Select操作

3254 ワード

JQuery Select操作
JQuery     Select        :   select        : $("#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    
select text : $("#ddlRegType").find("option:selected").text();
select value:
$("#nowamagic").val();
select :
$("#nowamagic").get(0).selectedIndex;
select 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 select : //index $("#nowamagic").get(0).selectedIndex=index;
select value:
$("#nowamagic").attr("value","Normal"); $("#nowamagic").val("Normal"); $("#nowamagic").get(0).value = value;
select text:
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; } }
select:
$("#nowamagic").empty();