自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

jQuery Select操作大集合

開發(fā) 前端
本文總結(jié)了jQuery獲取Select選擇的Text和Value;jQuery添加/刪除Select的Option項(xiàng)的Select操作,并給與了對應(yīng)的解釋。
jQuery獲取Select選擇的Text和Value:
語法解釋:
 
  1. $("#select_id").change(function(){//code...});    //為Select添加事件,當(dāng)選擇其中一項(xiàng)時(shí)觸發(fā)   
  2. var checkText=$("#select_id").find("option:selected").text();   //獲取Select選擇的Text   
  3. var checkValue=$("#select_id").val();   //獲取Select選擇的Value   
  4. var checkIndex=$("#select_id ").get(0).selectedIndex;   //獲取Select選擇的索引值  
  5. var maxIndex=$("#select_id option:last").attr("index");   //獲取Select***的索引值 jQuery設(shè)置Select選擇的Text和Value:   
語法解釋:
  1. $("#select_id ").get(0).selectedIndex=1;   //設(shè)置Select索引值為1的項(xiàng)選中   
  2. $("#select_id ").val(4);    //設(shè)置Select的Value值為4的項(xiàng)選中   
  3. $("#select_id option[text='jQuery']").attr("selected"true);    //設(shè)置Select的Text值為jQuery的項(xiàng)選中   
  4.  
  5.  
jQuery添加/刪除Select的Option項(xiàng):

語法解釋:
  1. $("#select_id").append("<option value='Value'>Text</option>");   //為Select追加一個(gè)Option(下拉項(xiàng))   
  2. $("#select_id").prepend("<option value='0'>請選擇</option>");   //為Select插入一個(gè)Option(***個(gè)位置)   
  3. $("#select_id option:last").remove();   //刪除Select中索引值***Option(***一個(gè))   
  4. $("#select_id option[index='0']").remove();   //刪除Select中索引值為0的Option(***個(gè))   
  5. $("#select_id option[value='3']").remove();   //刪除Select中Value='3'的Option   
  6. $("#select_id option[text='4']").remove();   //刪除Select中Text='4'的Option  


【編輯推薦】

責(zé)任編輯:張偉 來源: 博客園
相關(guān)推薦

2010-02-03 09:53:08

Python版本

2010-07-26 09:06:09

SQL Server游

2010-07-14 14:02:52

SQL Server數(shù)

2012-01-05 10:19:43

JavaScript

2011-07-04 10:33:22

QT

2011-07-26 09:48:47

Shell快捷鍵grepinit

2014-05-15 15:29:09

Android開發(fā)資源

2013-08-13 13:38:13

Android錯(cuò)誤解決

2011-06-21 10:44:32

QT QTE

2010-10-20 17:31:40

Fedora應(yīng)用

2010-02-24 10:52:24

IBM中端服務(wù)器

2010-06-09 17:00:43

UML試題

2009-08-24 11:04:56

2010-08-04 09:57:28

路由器

2010-10-12 14:28:54

2025-02-17 00:00:03

人工智能AI工具

2009-01-07 10:30:25

2014-06-12 17:02:46

世界杯手游

2018-12-17 09:00:00

大數(shù)據(jù)數(shù)據(jù)科學(xué)工具

2012-12-26 17:14:03

點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號