http://jsfiddle.net/latoyale/XgxCP/1/は、私が働いてフォーク作ら
// JSON data start
var data = [
[
{optionValue: 0,url: 'Choose Town',community: 'Choose Town'},
{optionValue: 1,url: '/dutchess/amenia',community: 'Amenia'},
{optionValue: 2,url: '/dutchess/arlington',community: 'Arlington'},
{optionValue: 3,url: '/dutchess/barrytown',community: 'Barrytown'}
],
[ {optionValue: 0,url: 'Choose Town',community: 'Choose Town'},
{optionValue: 32,url: '/orange/Campbell-hall',community: 'Campbell Hall'},
{optionValue: 33,url: '/orange/central-valley',community: 'Central Valley'},
{optionValue: 34,url: '/orange/chester',community: 'Chester'},
]
];
// JSON data end
$(function() {
$('#page-changer')[0].reset(); // resets form onload
var $county = $('#county');
var $township = $('#township');
function updateTownshipOptions(){
var selected = $county.val();
if (selected) {
options = [];
var selected_data = data[$county.val()-1];
for (var i=0; i<selected_data.length; i++) {
options.push('<option value="'+selected_data[i].optionValue+'">'+selected_data[i].community+'</option>');
}
$township.html(options.join(''));
}
}
updateTownshipOptions();
$county.change(updateTownshipOptions);
});
あなたは 'change'イベントにバインドするのではなく、'クリック'イベント。 – meagar