JQuery实现从XML中获取数据,插入下列选项框

wxj2011happy 2011-05-27 05:36:50

代码如下,无法插入到下列选项框,求教

<script type="text/javascript">
$(document).ready(function(){
getCountries();

$("#country").change(function(){
getItems('country','province');
});
$("#province").change(function(){
getItems('province','city');
});
$("#city").change(function(){
selectItem('city');
});
});
function loadXML(xmlpath){
var xmlDoc = null;
if(window.ActiveXObject){
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}else
if(document.implementatation && document.implementation.createDocument){
xmlDoc = document.implementation.createDocument("","",null);
}
else{
alert('dddddd');
}
xmlDoc.async = false;
xmlDoc.load(xmlpath);
return xmlDoc;
}
function getCountries(){
var oxml = loadXML("C:\Documents and Settings\Administrator\Desktop\location.xml");
if($(oxml).find("location > country").size()>0){
var countryHtml;
$(oxml).find("country").each(function(){
countryHtml += '<option value="'+$(this).attr("id")+'">'+$(this).attr("name")+'</option>';
}
)
alert(countryHtml);
$(countryHtml).html("#country");
}
}
function getItems(itemName,childItem){
selectItem(itemName);
var itemHtml = '<option value="0" selected="selected">请选择</option>';
if($(currentItem).find(childItem).size()>0){
$(currentItem).find(childItem).each(function(){
itemHtml += '<option value="'+$(this).attr("id")+'">'+$(this).attr("name")+'</option>';
})
$("#"+childItem).html(itemHtml);
}
}
function selectItem(itemName){
ocurrent = $("select[@name="+itemName+"] option[@selected]");
current_id=ocurrent.val();
currentItem=$(oxml).find(itemName+"[id="+current_id+"]");
currentItem_name=currentItem.attr("name");
currentItem_path = currentItem.attr("path");
$("#current"+itemName+"path").val(currentItem_path);
}
</script>
--------------------------------------------------------------------------------------------------------
//HTML代码如下
<body>
<input id="test" type="button" value="test"/>
First Name:<input id="firstname" type="text" name="firstname"/><span id="nametip" style="display:none" >ddddd</span><br/>
Last Name:<input id="lastname" type="text" name="lastname"/><br/>
结果显示:<br/>

<input id="hide" type="button" value="hide"/>
<input id="show" type="button" value="show"/><br/>
<div id="content" style="background-color:red">ddddddddddddddddddd<br/></div>
<div id="contentp" >eeeeeeeeeeeeeeeeeee</div>
内容显示:<br/>
<div id="result"></div>
结果显示:<br/>
<div id="display"></div>
国家:<select name="country" id="country" onchange="getItems('country','province');">
<option value="0" selected="selected">请选择</option>
</select>
省份:<select name="province" id="province" onchange="getItems('province','city');">
<option value="0" selected="selected">请选择</option>
</select>
地区:<select name="city" id="city" onchange="selectItem('city');">
<option value="0" selected="selected">请选择</option>
</select>
</body>
...全文
137 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
wxj2011happy 2011-06-13
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 hongmei85 的回复:]
function getCountries(){
var oxml = loadXML("C:\Documents and Settings\Administrator\Desktop\location.xml");
if($(oxml).find("location > country").size()>0){
var countryHtml;
$(oxml).find("country……
[/Quote]

改过后还是没效果
hongmei85 2011-06-09
  • 打赏
  • 举报
回复
function getCountries(){
var oxml = loadXML("C:\Documents and Settings\Administrator\Desktop\location.xml");
if($(oxml).find("location > country").size()>0){
var countryHtml;
$(oxml).find("country").each(function(){
countryHtml += '<option value="'+$(this).attr("id")+'">'+$(this).attr("name")+'</option>';
}
)
alert(countryHtml);
$("#country").html(countryHtml);}
}
hongmei85 2011-06-09
  • 打赏
  • 举报
回复
function getCountries(){
var oxml = loadXML("C:\Documents and Settings\Administrator\Desktop\location.xml");
if($(oxml).find("location > country").size()>0){
var countryHtml;
$(oxml).find("country").each(function(){
countryHtml += '<option value="'+$(this).attr("id")+'">'+$(this).attr("name")+'</option>';
}
)
alert(countryHtml);
$("#country").html("countryHtml");}
}
失去乐山贼 2011-06-09
  • 打赏
  • 举报
回复
wa~茫茫晕,帮你顶下吧。

87,990

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧