网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
07月01日漏签0天
javascript吧 关注:269,242贴子:906,425
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 1回复贴,共1页
<<返回javascript吧
>0< 加载中...

调了好久还是没调出来的bug!求解救

  • 取消只看楼主
  • 收藏

  • 回复
  • 小卫卫9块9
  • null
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
xml文档如下:

想实现用jquery形成联动那种下拉框
但是总是报错:

附上html代码和js代码:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="../jquery-1.11.1.js"></script>
<script type="text/javascript" src="testxml.js"></script>
</head>
<body>
<div id="wrapper">
<h1>jquery playground</h1>
<ul id="nav">
<li><a class="current" href="index.html">演示jquery中的ajax操作</a> </li>
<li><a href="#">XML方式请求数据</a></li>
</ul>
<div id="content">
<form id="locationForm" name="locationForm" method="post" action="">
国家:
<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>
</form>
</div>
</div>
</body>
</html>
textxml.js文件:
$(document).ready(function(){
oxml = LoadXML("location.xml");
getCountries();
$("#country").change(function(){
getItems(*country*,*province*);
});
$("#province").change(function(){
getItems(*province*,*city*);
});
$("#city").change(function(){
selectItem(*city*);
});
});
function LoadXML(apath)
{
var xmlDoc = null;
if(window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
}
else
{
if(document.implementation && document.implementation.createDocument)
{
try
{
xmlDoc = document.implementation.createDocument("","",null);
}catch (e)
{
alert("XMLDOC创建失败:"+ e.message);
}
}
else
{
alert("你的浏览器不能处理这个脚本");
}
}
try
{
xmlDoc.async = false;
xmlDoc.load(apath);
}catch (e)
{
alert("xml加载失败:"+ e.toString());
}
return xmlDoc;
}
function getCountries()
{
if($(oxml).find("location > country").size() > 0 )
{
var countryHtml;
$(oxml).find("country").each(function(){
countryHtml += *<option value="* + $(this).attr("id") + *">* + $(this).attr("name") + *</option>*;
});
$(countryHtml).appendTo("#country");
}
}
function getItems(itemName,childItem)
{
selectItem(itemName);
var itemHtml = *<option value="0" select="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);
}


  • 小卫卫9块9
  • null
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
手动顶!


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 1回复贴,共1页
<<返回javascript吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示