我在这段代码中做错了什么:
<form action="">
<select class="input-xlarge required" id="inputGender" name="inputGender">
<option value="">select</option>
<option value="m">male</option>
<option value="w">female</option>
</select>
<select class="input-xlarge" id="inputWeight" name="inputWeight">
<option value="">select</option>
</select>
<input type="submit" name="action" value="Book" />
</form>
var data = [
[
{"ID":"1", "desc":"(12)"},
{"ID":"2", "desc":"(5)"},
{"ID":"6", "desc":"(15)"}
]
[
{"ID":"0", "desc":"(49)"},
{"ID":"7", "desc":"(5)"}
]
];
$("#inputGender").change((function() {
var $persons = $("#inputWeight").empty();
$.each(data[$(this).val() - 1], function() {
$persons.append("<option value=" + this.ID + ">" + this.desc + "</option>");
});
});
);
选择该值m
后,我想填充此数据:
[
{"ID":"1", "desc":"(12)"},
{"ID":"2", "desc":"(5)"},
{"ID":"6", "desc":"(15)"}
]
在选择 id #inputWeight
。或者如果w
被选中则显示:
[
{"ID":"0", "desc":"(49)"},
{"ID":"7", "desc":"(5)"}
]
...但它不工作。
请问有什么想法吗?