0

我正在构建 jquery 下拉菜单,我的菜单代码是:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Accordion Menu Using jQuery</title>
<script type="text/javascript" language="javascript" src="jquery.js"></script>
<script>
function getCountries()
{
    var url ='http://localhost/scorefinal/include-xml/countries_leagues.xml';
    var xmlhttp,x,i,txt,xx,j;
    var cats = new Array();
    var name = new Array();
    var contest_name = new Array();
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            x=xmlhttp.responseXML.documentElement.getElementsByTagName("country");
            txt="<div id='firstpane' class='menu_list'>";

            for(i=0;i<x.length;i++)
            {//to get all country names & competions without country like(world cup,.....) from the xml file
                cats[i] = x[i].getAttribute('link_name');
                name[i] = x[i].getAttribute('name');
                txt=txt +"<p class='menu_head'>"+ name[i] +"</p>";
                txt=txt +"<div class='menu_body'>";
                xx=x[i].getElementsByTagName("contest");
                for(var v=0;v<xx.length;v++)
                {
                    contest_name[v] = xx[v].getAttribute('name');
                    txt=txt+"<a href='#'>"+contest_name[v]+"</a>";
                }
                txt=txt+"</div>";
            }
            txt=txt +"</div>";
            document.getElementById("countries").innerHTML=txt;
            //alert(document.getElementById("countries").innerHTML);
        }
    };
    xmlhttp.open("GET",url,true);
    xmlhttp.send();
}
</script>

<style type="text/css">
body {
    margin: 10px auto;
    font: 75%/120% Verdana,Arial, Helvetica, sans-serif;
}
.menu_list {    
    width: 150px;
}
.menu_head {
    padding: 5px 10px;
    cursor: pointer;
    position: relative;
    margin:1px;
    font-weight:bold;
    background: #eef4d3 url(left.png) center right no-repeat;
}
.menu_body {
    display:none;
}
.menu_body a{
  display:block;
  color:#006699;
  background-color:#EFEFEF;
  padding-left:10px;
  font-weight:bold;
  text-decoration:none;
}
.menu_body a:hover{
  color: #000000;
  text-decoration:underline;
  }
</style>
</head>
<body>
<div id='countries'></div>
<script>getCountries();</script>
</body>
<script type="text/javascript">
$(document).ready(function()
{
    //slides the element with class "menu_body" when paragraph with class "menu_head" is clicked 
    alert('test');
    $("#firstpane p.menu_head").click(function()
    {
        $(this).css({backgroundImage:"url(down.png)"}).next("div.menu_body").slideToggle(300).siblings("div.menu_body").slideUp("slow");
        $(this).siblings().css({backgroundImage:"url(left.png)"});
    });
});
</script>

</html>

我有一个 javascript 函数 getCountries() 来获取 XML 数据并构建菜单,现在菜单只显示当我单击任何 menu_head 时我无法获得子菜单。注意:我添加alert('test');以查看是否document.ready正常工作,我发现添加alert();菜单后,除 chrome 和 opera 之外的所有浏览器都可以正常工作,但这没有意义,因为当我删除警报时,菜单停止。

请如果有人可以帮助我,我在这个问题上工作了三天,但我什么也没得到???

4

1 回答 1

0

As per your question and related to chrome i am suspecting the xml parser on browser end and came through these final links .Go through .

XML parser not working  in chrome .Try for alternative (only my conclusion ).

Jquery xml parser not working in Chrome?

and

XML parsing in Chrome vs IE and Firefox

于 2013-01-31T15:26:44.277 回答