参考:http://www.cnblogs.com/liqiang665/archive/2007/09/25/905181.html
解决方案 »
- 怎么利用JS获取HtmlEditor的值
- js的变量
- js如何实现农公历结合组件的编写?
- JS 获取URL的问题
- 高分求助~~~~~在线解答(ASP.NET)
- JS 可以修改<input type="file" name="file">的值吗?
- 如何控制一个网页,使访问他的人不能刷新?
- 如何在设定optionname.options[optionname.length]=new Option("name","value")时让其被选择?
- 能用JavaScript禁止浏览者拷贝网页文本吗?
- zhangchunlei老兄进来拿分,见者有份
- 如何button实现控制多个select列表框?
- 在网上看到可以在地址栏里输入javascript:alert(document.lastModified)来知道网页的最后更新时间,但我试下来,怎么每个网页的最后更新时间都是当前系统时间呢
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312" />
<title>XML三级联动</title>
</head>
<body>
<select id="pro" onchange="getCity(this.value)"></select>
<select id="city" onchange="getCountry(this.value)"></select>
<select id="country"></select>
</body>
</html>
<script>
function getCity(v)
{
var FirstId="";
var city=document.getElementById("city");
city.options.length=0;
for(var i=0;i<City[v].length;i++)
{
if(i==0)
FirstId=City[v][i].value;
city.options.add(City[v][i]);
}
getCountry(FirstId);
}
function getCountry(v)
{
var c=document.getElementById("country");
c.options.length=0;
for(var i=0;i<Country[v].length;i++)
{
c.options.add(Country[v][i]);
}
}
var doc;
window.onload=function()
{
if(document.implementation&&document.implementation.createDocument)
{
doc=document.implementation.createDocument('','',null);
doc.onload=handler;
doc.load("three.xml");
}
else if(window.ActiveXObject)
{
doc=new ActiveXObject("Microsoft.XMLDOM");
doc.onreadystatechange=function(){if(doc.readyState==4)handler();}
doc.load("three.xml");
}
else alert("XML创建出错!");
}
var City=[];
var Country=[];
function handler()
{
var pro=document.getElementById("pro");
var city=document.getElementById("city");
var country=document.getElementById("country");
var ps=doc.getElementsByTagName("prov");
var Init=true;
for(var i=0;i<ps.length;i++)
{
var value1=ps[i].getAttribute("id");
var txt1=ps[i].getAttribute("text");
pro.options.add(new Option(txt1,value1));
var citys=ps[i].getElementsByTagName("city");
City[value1]=new Array();
for(var j=0;j<citys.length;j++)
{
var value2=citys[j].getAttribute("id");
var txt2=citys[j].getAttribute("text");
var op1=new Option(txt2,value2);
City[value1].push(op1);
if(Init)
city.options.add(op1);
Country[value2]=new Array();
var countrys=citys[j].getElementsByTagName("county");
for(var k=0;k<countrys.length;k++)
{
var value3=countrys[k].getAttribute("id")
var txt3=countrys[k].getAttribute("text")
var op2=new Option(txt3,value3);
if(Init)
country.options.add(op2);
Country[value2].push(op2);
}
}
Init=false;
}
}
</script>