81,092
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>_select</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script type="text/javascript">
var _sf = [{id:'1',value:'四川'},{id:'2',value:'云南'}];
var _ct = [{id:'1_1',pid:'1',value:'成都'},{id:'1_2',pid:'1',value:'内江'},{id:'2_1',pid:'2',value:'文山'},{id:'2_2',pid:'2',value:'昆明'}];
var _ar = [{id:'1_1_1',pid:'1_1',value:'武侯区'},{id:'1_1_2',pid:'1_1',value:'青羊区'},{id:'1_2_1',pid:'1_2',value:'内江一区'},{id:'1_2_2',pid:'1_2',value:'内江二区'},{id:'2_1_1',pid:'2_1',value:'文山一区'},{id:'2_1_2',pid:'2_1',value:'文山二区'},{id:'2_2_1',pid:'2_2',value:'昆明一区'},{id:'2_2_2',pid:'2_2',value:'昆明二区'}];
window.onload = function(){
document.getElementById('sf').options[0] = new Option('请选择','');
for(var i=0;i<_sf.length;i++){
document.getElementById('sf').options[i+1] = new Option(_sf[i].value,_sf[i].id);
}
document.getElementById('sf').onchange = function(){
var value = document.getElementById('sf').value;
if(value!="")getData(document.getElementById('ct'),_ct,value);
};
document.getElementById('ct').onchange = function(){
var value = document.getElementById('ct').value;
if(value!="")getData(document.getElementById('ar'),_ar,value);
};
}
function getData(id,arr,value){
//for(var i=0;i<id.options.length;i++)id.options.remove(i);
id.options.length = 0;
id.options[0] = new Option('请选择','');
for(var i = 0 ;i<arr.length;i++){
if(value==arr[i].pid)id.options[i+1] = new Option(arr[i].value,arr[i].id);
}
}
</script>
</head>
<body>
省份:<select id='sf'></select>
城市:<select id='ct'></select>
区域:<select id='ar'></select>
</body>
</html>