我有组合框(事实上,其中有几个),动态添加了元素。
使用jQuery,我不知道如何实现将返回在组合中选择的项目ID的函数...
我知道必须使用.live(),比如
$(".foo").live("change", function() {
do something;
});
...但我不知道如何在这里实施。
tnx in adv!
答案 0 :(得分:1)
在select元素的子元素上使用:selected
选择器(a.k.a. options)
$(".foo").live("change").function(){
var val = $(".foo").find(":selected").val();
// pass val to some other method for work
});
答案 1 :(得分:1)
你在找这样的东西吗?
$(".foo").live("change", function() {
$(this).val(); // value of the changed item
});
答案 2 :(得分:1)
$(".foo").live("change", function() {
alert($(this).attr("id")); // Id of the element
});
答案 3 :(得分:1)