国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

JQuery select標簽操作代碼段

2024-05-06 14:09:59
字體:
供稿:網(wǎng)友
下面幾個常用的代碼或許對您有幫助:
代碼如下:
//1.獲取選中option值
$('#selectList').val();
//2.獲取選中option的文本
$('#selectList :selected').text();
//3.獲取多個選中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.使用選項option的條件表達式
switch ($('#selectList :selected').text()) {
case 'First Option':
//do something
break;
case 'Something Else':
// do something else
break;
}
//5.刪除某個value=2的option
$("#selectList option[value='2']").remove();
//6.從list A 移動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,可以先看它的文檔。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 渑池县| 湟源县| 论坛| 凯里市| 西宁市| 松溪县| 溧阳市| 清流县| 隆回县| 准格尔旗| 霍林郭勒市| 卢湾区| 泰顺县| 家居| 漾濞| 甘德县| 屏东市| 海南省| 双鸭山市| 顺昌县| 蓬莱市| 布拖县| 陆川县| 九寨沟县| 勃利县| 益阳市| 贡觉县| 新平| 固阳县| 洛浦县| 北票市| 赤峰市| 盈江县| 甘肃省| 赞皇县| 普格县| 华亭县| 凯里市| 龙游县| 区。| 衡阳市|