我似乎无法让 jQuery 触发和更改county_id 选择列表的事件。我已经尝试了多个代码片段,但没有一个会触发更改。有任何想法吗?
HTML:
<select id="county_id" name="county_id">
<option value=""></option>
<option value="1">Somewhere</option>
<option value="2">Somewhere else</option>
</select>
<select id="vice_county_id" name="vice_county_id"></select>
JS:
$(function(ready) {
$("#county_id").change(
function() {
$("#vice_county_id").html("");
var co_id = $("#county_id > option[@selected]").attr("value");
if (co_id != 0) {
$.getJSON('./vice_county_web_service.php?co_id=' + co_id,
function(data) {
$.each(data, function() {
$("#vice_county_id").append(
$("<option></option>").val(
this['value']).html(
this['name']));
});
});
}
});
});