ajax填充的选择框上的Jquery委托函数(Jquery 2.0)

ajax填充的选择框上的Jquery委托函数(Jquery 2.0),jquery,delegates,Jquery,Delegates,我用onload选项(ajax,on-pageload)填充我的selectbox,效果很好 <select name="variety" id="resorts"><option value="">Select </option></select> 它似乎不起作用,但返回“未定义”。怎么了 也许是填充函数 function populate_cantons(){$.getJSON("http://skiweather.eu/v3/ajax/f

我用onload选项(ajax,on-pageload)填充我的selectbox,效果很好

<select name="variety" id="resorts"><option value="">Select </option></select> 
它似乎不起作用,但返回“未定义”。怎么了

也许是填充函数

function populate_cantons(){$.getJSON("http://skiweather.eu/v3/ajax/fetch_canton.php",{country:$("#country").val()},function(a){var b=$("#cantons");var c=b.prop("options");$("option",b).remove();$.each(a,function(a,b){c[c.length]=new Option(b["canton"])});b.prepend("<option selected>Select region</option>")})}
function populate_cantons(){$.getJSON(“http://skiweather.eu/v3/ajax/fetch_canton.php“,{country:$(“#country”).val()},函数(a){var b=$(“#cantons”);var c=b.prop(“options”);$(“option”,b).remove();$.each(a,function(a,b){c[c.length]=新选项(b[“cantons”)};b.prepend(“Select region”)}”
(选择页面右上角的方框。

尝试:

$("body").delegate("change", "#resorts", function(e){ 
   window.location='http://skiweather.eu/webcams/' + $(this).val();
   return false;
});

您尝试读取
属性,但您的
选项
元素没有此类属性。您可以添加它,也可以读取
选项
元素的文本。

我更喜欢将值添加到填充函数中,但我对如何操作有点困惑。.值属性可以作为
选项
构造器。因此,对于各州来说,它是
新选项(b[“canton”],b[“canton”])
对于度假村来说,可能是
新选项(b[“resort_us”],b[“resort_us”])
$("body").delegate("change", "#resorts", function(e){ 
   window.location='http://skiweather.eu/webcams/' + $(this).val();
   return false;
});
$(this).children("option:selected").attr("value");