2013-07-11 33 views
1

<select>元素被點擊時,沒有辦法填充<select>列表嗎?加載<options>改爲<select>當<select>被點擊時

$(document).ready(function(){ 
    $("body").on("click", "select", function(){ 
     ajax(); //should append additional <option>s to select 
    }); 
}); 

是否有任何解決方案加載<select>點擊時的內容?

http://jsfiddle.net/AxEAe/

編輯:

試圖周邊<select><div>和點擊事件附加到這一點。沒有運氣。

+0

你的小提琴似乎在工作 –

+0

@ᾠῗᵲᄐᶌ真的嗎?這不適合我;它只顯示前兩個靜態選項。 – 1252748

+0

是的,這很可能,正如你的小提琴所證明的那樣。打開並關閉幾次。問題在於select不會更新,除非您關閉並重新打開它,因爲ajax不是即時的。爲什麼你想要點擊它? –

回答

2
$("body").on("click", "select", function(){ 
     $(this).children('option:last').insertAfter('<option>Another option</option>'); 
});