<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
<!--
function read()
{
var request;
try {
request = new XMLHttpRequest();
}
catch(e){
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.open("get","test.xml",false);
request.send()
var bob=request.responseText;
alert("返回的信息为:"+bob)
}
//-->
</script>
</head>
<body>
<input id="name" name="name" type="button" Value="测试" onclick="return read();">
</body>
</html>text.xml
<team>
<title></title>
<link></link>
<team>我想从text.xml获取信息并把title与link内的值取出来,并给一个人变量即可,哪位高手帮个忙啊.

解决方案 »

  1.   

    一个例子,希望对lz有帮助//文件test.html
    <html>
    <head>
    <title>test.html</title>
    <script>
    function window_onload(){
    var xmlDoc= new ActiveXObject('Microsoft.XMLDOM');
    xmlDoc.async=false;
    xmlDoc.load(test.xml");
    var table_no=xmlDoc.getElementsByTagName('table_no')[0].text;
    var field_no=xmlDoc.getElementsByTagName('field_no')[0].text;
    var data_type=xmlDoc.getElementsByTagName('data_type')[0].text;
    alert(table_no);
    alert(field_no);
    alert(data_type);
    }
    </script>
    </head>
    <body onload="window_onload()">
    </body>
    </html>//文件test.xml
    <root>
    <table_no>33</table_no>
    <field_no>44</field_no>
    <data_type>55</data_type>
    </root>将上面2个文件放在同一个目录下,然后运行test.html