我有組合框(事實上,其中幾個),動態添加元素。jQuery - 如何在combobox上實現live()?
使用jQuery,我不知道如何實現函數將返回我在組合所選項目的ID ...
我知道,它有使用.live東西(是),像
$(".foo").live("change", function() {
do something;
});
...但我不知道如何在這裏實現它。
tnx in adv!
我有組合框(事實上,其中幾個),動態添加元素。jQuery - 如何在combobox上實現live()?
使用jQuery,我不知道如何實現函數將返回我在組合所選項目的ID ...
我知道,它有使用.live東西(是),像
$(".foo").live("change", function() {
do something;
});
...但我不知道如何在這裏實現它。
tnx in adv!
您正在尋找這樣的事情?
$(".foo").live("change", function() {
$(this).val(); // value of the changed item
});
使用上的選擇元素的子元素(又名選項)的:selected
選擇
$(".foo").live("change").function(){
var val = $(".foo").find(":selected").val();
// pass val to some other method for work
});
$(".foo").live("change", function() {
alert($(this).attr("id")); // Id of the element
});
我想這就是答案,如果他想選擇的id但我認爲如果你仔細閱讀,他正在尋找所選選項的價值 – hunter 2010-10-26 18:21:51