JQuery select標(biāo)簽操作代碼段
//1.獲取選中option值
$('#selectList').val();
//2.獲取選中option的文本
$('#selectList :selected').text();
//3.獲取多個(gè)選中option值、文本
var foo = [];
$('#multiple :selected').each(function(i, selected) {
foo[i] = $(selected).text();
});
// to get the selected values, just use .val() - this returns a string or array
foo = $('#multiple :selected').val();
//4.使用選項(xiàng)option的條件表達(dá)式
switch ($('#selectList :selected').text()) {
case 'First Option':
//do something
break;
case 'Something Else':
// do something else
break;
}
//5.刪除某個(gè)value=2的option
$("#selectList option[value='2']").remove();
//6.從list A 移動(dòng)option到 list B.
// here we have 2 select lists and 2 buttons. If you click the “add” button,
// we remove the selected option from select1 and add that same option to select2.
// The “remove” button just does things the opposite way around.
// Thanks to jQuery's chaining capabilities, what was once a rather tricky undertaking with JS can now be done in 6 lines of code.
$().ready(function() {
$('#add').click(function() {
return !$('#select1 option:selected').appendTo('#select2');
});
$('#remove').click(function() {
return !$('#select2 option:selected').appendTo('#select1');
});
});
如果您不了解JQuery,可以先看它的文檔。
- 50個(gè)比較實(shí)用jQuery代碼段
- 分享javascript、jquery實(shí)用代碼段
- 利用Jquery實(shí)現(xiàn)幾款漂亮實(shí)用的時(shí)間軸(附示例代碼)
- jQuery+ajax實(shí)現(xiàn)實(shí)用的點(diǎn)贊插件代碼
- 分享12個(gè)實(shí)用的jQuery代碼片段
- 基于jQuery實(shí)現(xiàn)美觀且實(shí)用的倒計(jì)時(shí)實(shí)例代碼
- 8個(gè)超實(shí)用的jQuery功能代碼分享
- 60個(gè)很實(shí)用的jQuery代碼開發(fā)技巧收集
- 一些實(shí)用的jQuery代碼片段收集
- jquery實(shí)用代碼片段集合
- 非常實(shí)用的jQuery代碼段集錦【檢測(cè)瀏覽器、滾動(dòng)、復(fù)制、淡入淡出等】
相關(guān)文章
jQuery Checkbox 全選 反選的簡(jiǎn)單實(shí)例
本文主要介紹了Checkbox的全選、反選的簡(jiǎn)單實(shí)例,需要的朋友可以參考下2016-11-11jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調(diào)器使用介紹
jQuery EasyUI API 中文文檔 - NumberSpinner數(shù)值微調(diào)器使用,需要的朋友可以參考下。2011-10-10jQuery-Easyui 1.2 實(shí)現(xiàn)多層菜單效果的代碼
早上打開郵箱,一位朋友問我之前JQuery-Easyui 怎么做可以實(shí)現(xiàn)多級(jí)菜單2012-01-01關(guān)于jQuery中fade(),show()起始位置的一點(diǎn)小發(fā)現(xiàn)
下面小編就為大家?guī)硪黄P(guān)于jQuery中fade(),show()起始位置的一點(diǎn)小發(fā)現(xiàn)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-04-04jquery實(shí)現(xiàn)從數(shù)組移除指定的值
這篇文章主要介紹了jquery實(shí)現(xiàn)從數(shù)組移除指定的值,涉及jQuery中g(shù)rep()方法對(duì)數(shù)組元素進(jìn)行過濾篩選的技巧,需要的朋友可以參考下2015-06-06JQuery動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法
下面小編就為大家?guī)硪黄狫Query動(dòng)態(tài)添加Select的Option元素實(shí)現(xiàn)方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-08-08基于jQuery的select下拉框選擇觸發(fā)事件實(shí)例分析
這篇文章主要介紹了基于jQuery的select下拉框選擇觸發(fā)事件實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了常用瀏覽器對(duì)select觸發(fā)事件的兼容及實(shí)現(xiàn)觸發(fā)的相關(guān)技巧,需要的朋友可以參考下2016-11-11比較簡(jiǎn)單的jquery教程 Easy Ajax with jQuery 中文版全集
比較簡(jiǎn)單的jquery教程 Easy Ajax with jQuery 中文版全集...2007-11-11