2011-03-17 100 views

回答

1

嘗試是這樣的:

$(document).ready(function(){ 

    $('#your_select').change(function(){ 
    var result = $(this).val(); 
    do_something_with(result); 
    }); 

}); 

假設HTML這樣的:

<select id="your_select" name="selectname"> 
    <option value="foo">Foo!</option> 
    <option value="bar">Bar!</option> 
</select> 
+0

確定,當您用鼠標選擇選擇,但不是當你喲ü使用箭頭鍵 – 2011-03-18 08:26:11

+0

如果您通過選擇菜單中的選項「箭頭」,則實際上並不是每次移動都會改變數值。當你「改變」這個改變時,你通常會通過點擊「enter」或「spacebar」來識別這個選項。這是'change'事件被觸發的時候。 – 2011-03-18 15:11:20

0
$('select').change(function() { 
    alert($(this).val()); 
}); 

JSFiddle Example

+0

確定當你用鼠標選擇而不是當你使用箭頭鍵時 – 2011-03-18 08:26:50

+0

@Kris當你選擇丟失焦點時它應該觸發事件,如果你使用的是鍵 – 2011-03-18 09:38:37