1. 獲取選中項:
復制代碼 代碼如下:
獲取選中項的Value值:
$('select#sel option:selected').val();
或者
$('select#sel').find('option:selected').val();
獲取選中項的Text值:
$('select#seloption:selected').text();
或者
$('select#sel').find('option:selected').text();
復制代碼 代碼如下:
$('select#sel').get(0).selectedIndex;
復制代碼 代碼如下:
$('select#sel option:last').attr("index")
復制代碼 代碼如下:
$('select#sel')[0].options.length;
或者
$('select#sel').get(0).options.length;
復制代碼 代碼如下:
$('select#sel option:first').attr('selected','true')
或者
$('select#sel')[0].selectedIndex = 0;
復制代碼 代碼如下:
$('select#sel option:last).attr('selected','true')
復制代碼 代碼如下:
$('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....
復制代碼 代碼如下:
$('select#sel').attr('value','4');
或者
$("select#sel option[value='4']").attr('selected', 'true');
復制代碼 代碼如下:
$("select#sel option[value='3']").remove();
復制代碼 代碼如下:
$(" select#sel option ").eq(索引值).remove();索引值=0,1,2....
如刪除第3個Radio:
$(" select#sel option ").eq(2).remove();
復制代碼 代碼如下:
$(" select#sel option ").eq(0).remove();
或者
$("select#sel option:first").remove();
復制代碼 代碼如下:
$("select#sel option:last").remove();
復制代碼 代碼如下:
$("select#sel").remove();
復制代碼 代碼如下:
$("select#sel").append("f");
復制代碼 代碼如下:
$("select#sel").prepend("0");
復制代碼 代碼如下:
$(' select#sel option ').each(function (index, domEle) {
//寫入代碼
});
新聞熱點
疑難解答
圖片精選