我已经将selection.php中的两个数组分配给 smarty 像这样
$country = array(
'1' => 'Japan',
'2' => 'Australia',
'3' => 'India'
);
$city = array(
'1' => array(
'10' => 'Tokyo',
'11' => 'Osaka'
),
'2' => array(
'20' => 'Sydney',
'21' => 'Melbourne'
),
'3' => array(
'30' => 'Mumbai',
'31' => 'Delhi'
)
);
$smarty->assign('country_select',$country);
$smarty->assign('city_select',$city);
$smarty->display('selection.tpl');
selection.tpl中的代码如下所示。
<div>{html_options id='country_select' options=$country_select}</div>
<div>{html_options id='city_select' options=$city_select}</div>
现在我要做的是,编写一个jQuery函数,当我在country_select下拉列表中选择一个国家时,city_select下拉列表中的项目将根据国家选择进行更改。这意味着,如果我在 country_select 下拉菜单中选择“Australia”,则在 city-select 下拉菜单中,除了“Sydney”和“Melbourne”之外,其他选项将被删除。
你能帮我看看jQuery代码是怎样的吗?我未能将 $city_select 数组传递给 jQuery。