1<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
2<head>
3<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
4<meta content="no-cache" http-equiv="pragma"/>
5<style type="text/css">
6<!--
7\-->
8</style>
9<script language="JavaScript">
10<!--
11/*****************************************************************************************
12ClearDropDownList(目标Object,是否保留第一个)
13*****************************************************************************************/
14function ClearDropDownList(oSel,bolLeaveFirst)
15{
16if(oSel==null ¦ ¦ oSel.tagName.toLowerCase()!='select'){
17alert('SELECT控件不存在!\n'+oSel.tagName);
18return;}
19var iLength=oSel.options.length;
20if(bolLeaveFirst)
21iTmp=1;
22else
23iTmp=0;
24for(iCnt=iLength-1;iCnt>=iTmp;iCnt--)
25oSel.options.remove(iCnt);
26oSel=null;
27}
28//////////////////////////////////////////////////////////////////////////////
29var oDom=new ActiveXObject('Microsoft.XMLDOM');
30oDom.async=true;
31oDom.onreadystatechange=loadDataProcess;
32function loadDataMain(){
33ClearDropDownList(selTest,false);
34var opn=new Option;
35opn.text='正在装载,请等待...'
36selTest.options.add(opn);
37btnTest.disabled=true;
38selTest.disabled=true;
39oDom.load('city.xml');
40}
41function loadDataProcess(){
42if(oDom.readyState==4){
43if(oDom.parseError.errorCode==0){
44btnTest.disabled=false;
45for(var iCnt=0;iCnt<oDom.documentElement.childNodes.length;iCnt++){
46var opn=new Option;
47opn.text=oDom.documentElement.childNodes[iCnt].getAttribute('NAME');
48opn.value=oDom.documentElement.childNodes[iCnt].getAttribute('CODE');
49selTest.options.add(opn);
50}
51selTest.options.remove(0);
52selTest.onchange=function (){
53alert('你选中了'+this.value);
54}
55selTest.disabled=false;
56}else{
57selTest.options[0].text='装载失败!';
58}
59}else{
60selTest.options[0].text+='...';
61}
62}
63\-->
64</script>
65<title></title>
66</head>
67<body>
68<select disabled="" name="selTest" style="width:300px;">
69<option>请点击装载数据按钮</option>
70</select><br/><br/>
71<button disabled="" id="btnTest" onclick="javaScript:alert('我可以用了!');">测试按钮</button>
72<button onclick="javaScript:loadDataMain();">装载数据</button>
73</body>
74</html>
贴一个XMLDOM的异步加载例子
comments powered by Disqus