日期:2014-05-16  浏览次数:20396 次

firefox java操作数组的问题!!
js文件

var   toDayDataAry=new   Array();

function   m_loadXML()
{
var   nodeTags   =   xmlDoc.getElementsByTagName( "game ");
for(i=0;i   <   nodeTags.length;i++)
{
toDayDataAry[i]=new   Array();
toDayDataAry[i][0]=nodeTags[i].getAttribute( "gametype ");
toDayDataAry[i][1]=nodeTags[i].getAttribute( "startdate ");  
toDayDataAry[i][2]=nodeTags[i].getAttribute( "startTime ");
toDayDataAry[i][3]=nodeTags[i].getAttribute( "gameStateTag ");
toDayDataAry[i][4]=nodeTags[i].getAttribute( "gameState ");
toDayDataAry[i][5]=nodeTags[i].getAttribute( "familyTeam ");
}
}
function   printS()
{
for(i=0;i <toDayDataAry.length;i++)
{
alert(toDayDataAry[i][0])
}

}
xml文件
<?xml   version= "1.0 "   encoding= "gb2312 "?>
<scores>
    <game   gametype= "冰甲 "   startdate= "2007-7-6 "   startTime= "04:00 "   gameStateTag= "2 "   gameState= "下 "   familyTeam= "雷尼桑格迪 "   familyScore= "3 "   teamScore= "0-2 "   guestScore= "2 "   guestTeam= "格连戴域克 "   halfScore= "0-0 "   gameColor= "#336699 "   gameid= "1 "   gameWZDate= "2007-7-6   4:00:00 "   startMinute= "90+ "   keyWord= "冰甲:雷尼桑格迪-格连戴域克 "/>
    <game   gametype= "世青盃 "   startdate= "2007-7-6 "   startTime= "05:00 "   gameStateTag= "2 "   gameState= "下 "   familyTeam= "新西兰U20 "   familyScore= "0 "   teamScore= "0-1 "   guestScore= "1 "   guestTeam= "冈比亞U20 "   halfScore= "0-1 "   gameColor= "#336699 "   gameid= "2 "   gameWZDate= "2007-7-6   5:00:00 "   startMinute= "90+ "   keyWord= "世青盃:新西兰U20-冈比亞U20 "/>
    <game   gametype= "美洲盃 "   startdate= "2007-7-6 "   startTime= "06:30 "   gameStateTag= "2 "   gameState= "下 "   familyTeam= "哥伦比亚 "   familyScore= "1 "   teamScore= "1-0 "   guestScore= "0 "   guestTeam= "美国 "   halfScore= "1-0 "   gameColor= "#336699 "   gameid= "3 "   gameWZDate= "2007-7-6   6:30:00 "   startMinute= "90+ "   keyWord= "美洲盃:哥伦比亚-美国 "/>
</scores>
firefox:
在m_loadXML()中调用printS()可以输出数组内容,外部调用不能输出,数组langth是0,
在ie中是可以的。
给怎么修改此段代码,才能在firefox下正常输出。

------解决方案--------------------
应该是你写的new ActiveXObject有问题.

IE是这么写
var xmlDoc = new ActiveXObject( "msxml.domdocument ");

FIREFOX下是这样的:
var oParser = new DOMParser();
var xmlDoc = oParser.parseFromString(sXML, "text/xml ");
------解决方案--------------------
另外
var nodeTags = xmlDoc.getElementsByTagName( "game ");
最好写成
var nodeTags = xmlDoc.selectNodes( "//scores/game ");