Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jQuery-如何在combobox上实现live()?_Jquery_Combobox_Live - Fatal编程技术网

jQuery-如何在combobox上实现live()?

jQuery-如何在combobox上实现live()?,jquery,combobox,live,Jquery,Combobox,Live,我有combobox(实际上有几个),其中的元素是动态添加的 使用jQuery,我不知道如何实现返回我在combo中选择的项id的函数 我知道它必须是使用.live()之类的东西 $(".foo").live("change", function() { do something; }); 。。。但我不知道如何在这里实现它 tnx在adv 在select元素(也称为选项)的子元素上使用:selected选择器 在select元素(也称为选项)的子元素上使用:selected选择器 你在找这样的

我有combobox(实际上有几个),其中的元素是动态添加的

使用jQuery,我不知道如何实现返回我在combo中选择的项id的函数

我知道它必须是使用.live()之类的东西

$(".foo").live("change", function() {
do something;
});
。。。但我不知道如何在这里实现它


tnx在adv

在select元素(也称为选项)的子元素上使用
:selected
选择器


在select元素(也称为选项)的子元素上使用
:selected
选择器


你在找这样的东西吗

$(".foo").live("change", function() {
  $(this).val(); // value of the changed item
});

你在找这样的东西吗

$(".foo").live("change", function() {
  $(this).val(); // value of the changed item
});
您可以使用
$(this).val()
查找触发事件的元素的值

看来是别人抢先了我一步。我的和约翰和丹尼尔一样

这里有一个JSFIDLE来测试它

需要注意的一点是,live并不支持所有浏览器(如IE6到IE8)中的change方法

解决这个问题的一种方法是使用委托方法,我已经演示过了

它看起来像:

$(parentElement).delegate(selector, 'change', function() {
    //do something interesting here
    //$(this).val() still works.
});
您可以使用
$(this).val()
查找触发事件的元素的值

看来是别人抢先了我一步。我的和约翰和丹尼尔一样

这里有一个JSFIDLE来测试它

需要注意的一点是,live并不支持所有浏览器(如IE6到IE8)中的change方法

解决这个问题的一种方法是使用委托方法,我已经演示过了

它看起来像:

$(parentElement).delegate(selector, 'change', function() {
    //do something interesting here
    //$(this).val() still works.
});

如果他想要选择元素的id,我认为这是答案,但如果你仔细阅读,我认为他在寻找所选选项的值。如果他想要选择元素的id,我认为这是答案,但如果你仔细阅读,我认为他在寻找所选选项的值