DIV CSS 佈局教程網

jQuery Select 操作方法大全:取值、設定與增刪選項
編輯:JQuery特效代碼     

jQuery 操作 select 可分為取值、設定、增刪與 optgroup 處理。

取值

  • 第一個選項:$('#test option:first').val()
  • 最後一個選項:$('#test option:last').val()
  • 指定索引:$('#test option:eq(1)').val()
  • 目前選中:$('#test').val()

設定與移除

可用 attr 設定 selected,也可用 each 逐一檢查後刪除。若要移除指定值,可用屬性選擇器直接刪除。

optgroup

若 select 有分組,可用 optgroup:eq(0) 取得標籤,或取得特定 group 下的第一個 option。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved