DIV CSS 佈局教程網

用 jQuery 將 DropDownList 選中值帶入 Label
編輯:JQuery特效代碼     

想讓下拉選單的選擇即時反映到旁邊的文字標籤上,只要監聽 change 事件即可。

寫法一:取選中項的文字

$(function() { $("#DropDownList1").bind("change", function() { $("#Label1").text($("#DropDownList1 option:selected").text()); }); });

寫法二:取選中項的值

$("#DropDownList1").bind("change", function() { $("#Label1").text($("#DropDownList1").val()); });

兩者的差別在於取的是文字還是值,可視需求挑選。補充說明取值方式:

var name = $("#DropDownList1 option:selected").val(); // 取得選中項的值 var name1 = $("#DropDownList1").text(); // 取得下拉選單的全部文字

只要掌握 option:selected 這個選擇器,就能輕鬆讀取使用者當前的選擇。

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