jQuery操作select下拉框的text值和value值的方法

來源:互聯網
上載者:User

標籤:style   blog   color   io   ar   sp   div   on   cti   

1、jquery擷取當前選中select的text值 

var checkText=$("#slc1").find("option:selected").text(); 

2、jquery擷取當前選中select的value值 

var checkValue=$("#slc1").val(); 

3、jquery擷取當前選中select的索引值 

var index=$("#slc1 ").get(0).selectedIndex; 

4、jquery設定索引值為1的項為當前選中項 

$("#slc1 ").get(0).selectedIndex=1; 

5、jquery設定value值2的項為當前選中項 

$("#slc1 ").val(2); 

6、jquery設定text值為"青藤園"的項為當前選中項 

$("#slc1 option[text=‘青園w‘]").attr("selected",true); 

7、為指定select下拉框追加一個option(追加到在末尾) 

$("#slc2").append(""+i+""); 

8、為制定select下拉框插入一個option(插入到第一個位置) 

$("#slc2").prepend("請選擇"); 

9、jquery刪除select下拉框的最後一個option 

$("#slc2 option:last").remove();

 

select改變值時用onchange方法

<select id="selectw" onchange="magchange()">                       <option value="2"></option>                       <option value="1">微博</option>                   </select>

選擇時擷取當前選擇的value值

function magchange(){        var checkValue=$("#selectw").val();        return checkValue;}

 

jQuery操作select下拉框的text值和value值的方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.