87,910
社区成员
发帖
与我相关
我的任务
分享
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="zh-CN" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
jQuery(function($) {
$("#city").bind("change",function(){
$.ajax({
url: "XMLFile.xml",
success: function(xml){
var td = $(xml).find("td[title='"+$("#city").val()+"']:first");
$("#res").html(td.text());
}
});
});
});
</script>
</head>
<body>
<select id="city">
<option value="北京">北京</option>
<option value="上海">上海</option>
</select>
<div id="res"></div>
</body>
</html>
<?xml version="1.0" encoding="utf-8" ?>
<tr>
<td title="北京">
<address>海淀区</address>
<sction>货到付款</sction>
<fu>城区不送</fu>
</td>
<td title="上海">
<adress>徐汇区</adress>
<sction>网上支付</sction>
<fu>可服务区除外</fu>
</td>
</tr>
<html>
<head>
<title></title>
<script language="javascript" type="text/javascript">
function loadXMLDoc(dname)
{
try // Internet Explorer
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try // Firefox, Mozilla, Opera, etc.
{
xmlDoc = document.implementation.createDocument("", "", null);
}
catch(e)
{
alert(e.message)
}
}
try
{
xmlDoc.async = false;
xmlDoc.load(dname);
return(xmlDoc);
}
catch(e)
{
alert(e.message)
}
return(null);
}
function test(cityName)
{
xmlDoc = loadXMLDoc('1.xml');
x = xmlDoc.getElementsByTagName('td');
for (i = 0; i < x.length; i ++ )
{
var c = x[i].children;
// 取得xml中的 td 的属性 title
if(x[i].getAttribute('title') == cityName)
{
for(var j=0;j<c.length;j++){
document.getElementById('res').innerHTML += c[j].nodeName+":"+c[j].childNodes[0].nodeValue;
}
}
}
}
</script>
</head>
<body>
<select id="city" onchange="test(this.value)">
<option value="北京">北京</option>
<option value="上海">上海</option>
</select>
<div id="res"></div>
</body>
</html>