最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

jquery下拉select控件操作方法分享(jquery操作select)

 更新時間:2014年03月25日 15:59:25   作者:  
這篇文章主要介紹了jquery下拉select控件操作方法分享(jquery操作select),需要的朋友可以參考下

JQuery獲取和設置Select選項方法匯總如下:

代碼:

復制代碼 代碼如下:

$("#select_id").change(function(){//code...});   //為Select添加事件,當選擇其中一項時觸發(fā)
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();

相關文章

最新評論

崇州市| 洮南市| 大兴区| 梓潼县| 山东| 突泉县| 承德县| 桦川县| 汝南县| 漯河市| 旌德县| 嘉鱼县| 呼玛县| 兴化市| 镇安县| 长乐市| 雷波县| 盘山县| 黄梅县| 丹巴县| 安岳县| 盐山县| 乌鲁木齐县| 虎林市| 鹤山市| 武邑县| 日喀则市| 榆树市| 四子王旗| 湖北省| 沂南县| 霞浦县| 合肥市| 五莲县| 双峰县| 巨野县| 富阳市| 施甸县| 项城市| 郧西县| 宁武县|