jQuery对select的操作

jQuery對select的操作

//改變時的事件
$("#testSelect").change(function(){ //事件發生
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變為selected
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
原文地址:
http://kevyu.blogspot.com/2008/03/jqueryselect.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值