欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

JQuery select(下拉框)操作方法匯總

 更新時(shí)間:2015年04月15日 13:16:55   投稿:junjie  
這篇文章主要介紹了JQuery select(下拉框)操作方法匯總,本文講解了獲取選中項(xiàng)、獲取當(dāng)前選中項(xiàng)的索引值、獲取當(dāng)前option的最大索引值、獲取DropdownList的長度等內(nèi)容,需要的朋友可以參考下

1. 獲取選中項(xiàng):
獲取選中項(xiàng)的Value值:

復(fù)制代碼 代碼如下:

$('select#sel option:selected').val();

或者
復(fù)制代碼 代碼如下:

$('select#sel').find('option:selected').val();

獲取選中項(xiàng)的Text值:
復(fù)制代碼 代碼如下:

$('select#seloption:selected').text();

或者
復(fù)制代碼 代碼如下:

$('select#sel').find('option:selected').text();

2.   獲取當(dāng)前選中項(xiàng)的索引值:
復(fù)制代碼 代碼如下:

$('select#sel').get(0).selectedIndex;

3.   獲取當(dāng)前option的最大索引值:
復(fù)制代碼 代碼如下:

$('select#sel option:last').attr("index")

4.   獲取DropdownList的長度:
復(fù)制代碼 代碼如下:

$('select#sel')[0].options.length;

或者
復(fù)制代碼 代碼如下:

$('select#sel').get(0).options.length;

5.  設(shè)置第一個(gè)option為選中值:
復(fù)制代碼 代碼如下:

$('select#sel option:first').attr('selected','true')

或者
復(fù)制代碼 代碼如下:

$('select#sel')[0].selectedIndex = 0;

6.   設(shè)置最后一個(gè)option為選中值:
復(fù)制代碼 代碼如下:

$('select#sel option:last).attr('selected','true')

7.   根據(jù)索引值設(shè)置任意一個(gè)option為選中值:
復(fù)制代碼 代碼如下:

$('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....

8.   設(shè)置Value=4 的option為選中值:
復(fù)制代碼 代碼如下:

$('select#sel').attr('value','4');

或者
復(fù)制代碼 代碼如下:

$("select#sel option[value='4']").attr('selected', 'true');

9.   刪除Value=3的option:
復(fù)制代碼 代碼如下:

$("select#sel option[value='3']").remove();

10.刪除第幾個(gè)option:
復(fù)制代碼 代碼如下:

$(" select#sel option ").eq(索引值).remove();索引值=0,1,2....

如刪除第3個(gè)Radio:
復(fù)制代碼 代碼如下:

$(" select#sel option ").eq(2).remove();

11.刪除第一個(gè)option:
復(fù)制代碼 代碼如下:

$(" select#sel option ").eq(0).remove();

或者
復(fù)制代碼 代碼如下:

$("select#sel option:first").remove();

12. 刪除最后一個(gè)option:
復(fù)制代碼 代碼如下:

$("select#sel option:last").remove();

13. 刪除dropdownlist:
復(fù)制代碼 代碼如下:

$("select#sel").remove();

14.在select后面添加一個(gè)option:
復(fù)制代碼 代碼如下:

$("select#sel").append("<option value='6'>f</option>");

15. 在select前面添加一個(gè)option:
復(fù)制代碼 代碼如下:

$("select#sel").prepend("<option value='0'>0</option>");

16. 遍歷option:
復(fù)制代碼 代碼如下:

$(' select#sel option ').each(function (index, domEle) {
//寫入代碼
});

相關(guān)文章

最新評論