jQuery select的操作實現(xiàn)代碼
更新時間:2009年05月06日 02:47:04 作者:
jQuery對select的操作的實際應(yīng)用代碼。方便大家學習jquery
//改變時的事件
$("#testSelect").change(function(){ //事件發(fā)生
jQuery('option:selected', this).each(function(){ //印出選到多個值
alert(this.value);
});
});
//印出選到的項目
法1:$("select#Clubs").children("[@selected]").each(function(){
alert(this.text);
});
法2:$("#selBags").val(); //這個比較快啦,但限單選
//取得下拉選單的選取值
$(#testSelect option:selected').text();
或$("#testSelect").find('option:selected').text();
//移除
removeOption(index/value/regex[, selectedOnly])
$('select#Clubs option:selected').remove();
//使某option變?yōu)閟elected
var select = $(tdsEdit[0]).find("select"); //取得select
$(select).children().each(function(){
if ($(this).text()=="option you want")
//jQuery給法
$(this).attr("selected","true"); //或是給selected也可
//javascript給法
this.selected = true;
});
參考
http://www.texotela.co.uk/code/jquery/select/
http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery.html
復制代碼 代碼如下:
$("#testSelect").change(function(){ //事件發(fā)生
jQuery('option:selected', this).each(function(){ //印出選到多個值
alert(this.value);
});
});
//印出選到的項目
復制代碼 代碼如下:
法1:$("select#Clubs").children("[@selected]").each(function(){
alert(this.text);
});
法2:$("#selBags").val(); //這個比較快啦,但限單選
//取得下拉選單的選取值
復制代碼 代碼如下:
$(#testSelect option:selected').text();
或$("#testSelect").find('option:selected').text();
//移除
removeOption(index/value/regex[, selectedOnly])
復制代碼 代碼如下:
$('select#Clubs option:selected').remove();
//使某option變?yōu)閟elected
復制代碼 代碼如下:
var select = $(tdsEdit[0]).find("select"); //取得select
$(select).children().each(function(){
if ($(this).text()=="option you want")
//jQuery給法
復制代碼 代碼如下:
$(this).attr("selected","true"); //或是給selected也可
//javascript給法
this.selected = true;
});
參考
http://www.texotela.co.uk/code/jquery/select/
http://blog.jeremymartin.name/2008/02/easy-multi-select-transfer-with-jquery.html
您可能感興趣的文章:
- jquery select(列表)的操作(取值/賦值)
- Jquery操作radio,checkbox,select表單操作實現(xiàn)代碼
- Jquery Select操作方法集合腳本之家特別版
- jQuery select操作控制方法小結(jié)
- 利用jquery操作select下拉列表框的代碼
- jquery操作select option 的代碼小結(jié)
- jQuery操作Select選擇的Text和Value(獲取/設(shè)置/添加/刪除)
- JQuery操作Select的Options的Bug(IE8兼容性視圖模式)
- 淺析jQuery對select操作小結(jié)(遍歷option,操作option)
- jQuery操作Select的Option上下移動及移除添加等等
- jquery操作select詳解(取值,設(shè)置選中)
- jquery 操作兩個select實現(xiàn)值之間的互相傳遞
- jquery操作select大全
- jQuery操作select下拉框的text值和value值的方法
- Jquery對select的增、刪、改、查操作
相關(guān)文章
JQuery報錯Uncaught TypeError: Illegal invocation的處理方法
這篇文章主要介紹了JQuery報錯"Uncaught TypeError: Illegal invocation"的處理方法,需要的朋友可以參考下2015-03-03
JQuery設(shè)置獲取下拉菜單某個選項的值(比較全)
這篇文章主要介紹了JQuery如何設(shè)置獲取下拉菜單某個選項的值(比較全),需要的朋友可以參考下2014-08-08

