我填充我的选项选择框的onload(阿贾克斯,在页面加载),并且工作正常jQuery的委托功能填充的选择框(jQuery的2.0)
<select name="variety" id="resorts"><option value="">Select </option></select>
要触发选项(转到URL)我使用下面的功能。
("body").delegate("#resorts","change", function(e){
window.location='http://skiweather.eu/webcams/' + $(this).children("option:selected").attr("value");
return false;
});
它似乎不工作,它返回'未定义'。哪里不对。
也许填充函数?
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>")})}
http://skiweather.eu/latest/(选择框位于页面右上角
我更喜欢将值添加到填充函数,但我对如何做到这一点有些困惑。 – mark 2013-04-22 15:36:58
value属性可作为Option的第二个参数提供给构造函数。因此,对于各州来说,它可能是新选项(b [“resort_us”],b [“resort_us”])''的新选项(b [“canton”],b [“canton”])''。 – zeroflagL 2013-04-22 16:12:23
谢谢zeroflagL!有用 – mark 2013-04-22 16:26:56