我有一个HTML选择元素,是通过以下PHP数组生成的:
$countries = array(
array('iso' => 'AF', 'name' => 'Afghanistan', 'key' => 'Red'),
array('iso' => 'AX', 'name' => 'Åland Islands','key' => 'Yellow'),
array('iso' => 'AL', 'name' => 'Albania', 'key' => 'Blue')
);
$select = '<select id="country_select" onchange="countryfind()">';
foreach($countries as $country) {
$select .= '<option value="'.$country['key'].'">'.$country['name'].'</option>';
}
$select = '</select>';
return $select;
function countryfind(){
jQuery('#countrykey').text(
jQuery('#country_select option:selected').val()
)};
我现在希望使用这个键与另一个包含国家信息的PHP数组交互,在#countrykey div中显示该国家而不是所选值:
$si_federations = array(
'Red' => array('name'=>'A Red Country', 'url'=>'http://www.redcountry.com'),
'Blue' => array('name'=>'A Blue Country', 'url'=>'http://www.soroptimisteurope.org'),
);
这是一件容易实现的事情吗,还是我的方法完全错误?