こんにちは、州ごとに並べられた特定の国の州のリストを生成するこのスマートなコードがあります ISO コード
countries = new Array();
{foreach from=$countries item='country'}
{if isset($country.states)}
countries[{$country.id_country|intval}] = new Array();
{foreach from=$country.states item='state' name='states'}
countries[{$country.id_country|intval}]['{$state.id_state|intval}'] = '{$state.name|escape:'htmlall':'UTF-8'}';
{/foreach}
{/if}
{/foreach}
ISOコードで注文されているので、結果はこれで大丈夫です
countries = new Array();
countries[10] = new Array();
countries[10]['53'] = 'AG';
countries[10]['54'] = 'AL';
countries[10]['55'] = 'AN';
countries[10]['56'] = 'AO';
countries[10]['58'] = 'AP';
countries[10]['93'] = 'AQ';
countries[10]['57'] = 'AR';
countries[10]['59'] = 'AT';
countries[10]['60'] = 'AV';
countries[10]['61'] = 'BA';
countries[10]['64'] = 'BG';
countries[10]['65'] = 'BI';
countries[10]['62'] = 'BL';
countries[10]['63'] = 'BN';
countries[10]['66'] = 'BO';
countries[10]['69'] = 'BR';
countries[10]['68'] = 'BS';
countries[10]['162'] = 'BT';
countries[10]['67'] = 'BZ';
countries[10]['70'] = 'CA';
countries[10]['72'] = 'CB';
countries[10]['73'] = 'CE';
countries[10]['76'] = 'CH';
countries[10]['156'] = 'CI';
countries[10]['71'] = 'CL';
countries[10]['81'] = 'CN';
countries[10]['77'] = 'CO';
countries[10]['79'] = 'CR';
countries[10]['78'] = 'CS';
countries[10]['74'] = 'CT';
countries[10]['75'] = 'CZ';
countries[10]['82'] = 'EN';
同じページに、選択したhtmlタグを設定するこのjavascriptがありますが、ISOコードではなくIDでオプションタグを注文し、理由がわかりません
$(document).ready(function(){
$('select#id_country').change(function(){
updateState();
});
updateState();
});
function updateState()
{
$('select#id_state option:not(:first-child)').remove();
var states = countries[$('select#id_country').val()];
if( typeof(states) != 'undefined' )
{
for (indexState in states)
{
//ie bug fix
if (indexState != 'indexOf')
$('select#id_state').append('<option value="'+indexState+'"'+ (idSelectedCountry == indexState ? ' selected="selected' : '') + '">'+states[indexState]+'</option>');
}
$('p.id_state:hidden').slideDown('slow');
}
else
$('p.id_state').slideUp('fast');
}