嗨在国家下拉列表中添加事件onchange并切换selectedValue,如果它是其中一个国家没有城市隐藏下拉列表并显示文本框,反之亦然。
<select id="country" onchange="check(this)">
<option value="Select">Select</option>
<option value="USA">USA</option>
<option value="EG">EG</option>
</select>
<select id="s_city">
</select>
<input type="text" id="t_city" style="display:none;">
脚本
function check(s)
{
document.getElementById('t_city').value ='';
document.getElementById('s_city').innerHTML='';
var c= s.options[s.selectedIndex].value;
//Here You Can Start Loading your states with each country
if(c !="USA")
{
document.getElementById('t_city').style.display='block';
document.getElementById('s_city').style.display='none';
}
else
{
document.getElementById('t_city').style.display='none';
document.getElementById('s_city').style.display='block';
}
}
我希望这个例子帮助了
如果你希望你的解决方案,以降低漂亮,你应该依靠最低要求(文本框可用于每个人),并通过JavaScript皮条客它来获得的下拉菜单 – 2011-05-03 11:13:10
你可能是对的(不,你绝对是对的),但我虽然上面的脚本足以让某人指向正确的方向,因此是笔记。 – 2011-05-03 11:16:53