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

请问为什么我的JS红色部分注销掉在firefox下就无法使用
JS:  
  var url = "config/PreciousMetal.xml";
  var i = 0;
  String.prototype.Trim = function() { return this.replace(/(^s*)|(s*$)/g, "");}
  var xmlDoc;//判断是否为Firefox或IE 
  var moz = (typeof document.implementation != 'undefined') && (typeof document.implementation.createDocument != 'undefined');
  var ie = (typeof window.ActiveXObject != 'undefined');

   
  function importXML(file) {
  if (moz) {
  xmlDoc = document.implementation.createDocument("", "doc", null); //创建FIREFOX下XML文档对象
  }
  else if (ie) {
  xmlDoc = new ActiveXObject("MSXML2.DOMDocument.3.0");
  xmlDoc.async = false;
  while (xmlDoc.readyState != 4) { }; //创建IE下XML文档对象 
  }
  xmlDoc.load(file);
  }
  importXML(url); //载入xml 
  Utils.$("price").innerHTML = "tupian";
  function updatetupiandizhi() {
  if (moz) {
  //alert("1");  
 var tupian;
  var ad = xmlDoc.getElementsByTagName("PreciousMetalConfigInfo")[0];
  var _tupian = ad.getElementsByTagName("PtBuyPrice")[0].firstChild.nodeValue;
  if (_tupian) tupian = _tupian.Trim(); //得到tupian,dizhi节点下的值
  document.getElementById("price").innerHTML = tupian;
   
  } else if (ie) {
  var src = xmlDoc.documentElement.selectNodes("PtBuyPrice");
  alert(src(i).text);
  } else {
   
  }
  }
  updatetupiandizhi();

XML文档内容

<?xml version="1.0"?>
<PreciousMetalConfigInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <PtBuyPrice price="365.58">365.58</PtBuyPrice>
  <AuBuyPrice>295.04</AuBuyPrice>
  <AgBuyPrice>5.36</AgBuyPrice>
  <PtSellPrice>364.08</PtSellPrice>
  <AuSellPrice>294.89</AuSellPrice>
  <AgSellPrice>5.26</AgSellPrice>
  <IPtClosePrice>1709.5</IPtClosePrice>
  <IPtCurentPrice>1700.5</IPtCurentPrice>
  <IPtUpDown>-9.0</IPtUpDown>
  <IAuClosePrice>1380.5</IAuClosePrice>
  <IAuCurentPrice>1377.1</IAuCurentPrice>
  <IAuUpDown>-3.4</IAuUpDown>
  <IAgClosePrice>24.61</IAgClosePrice>
  <IAgCurentPrice>24.59</IAgCurentPrice>
  <IAgUpDown>-0.02</IAgUpDown>
  <TJAgSellPrice>5263</TJAgSellPrice>
  <TJAgBuyPrice>5273</TJAgBuyPrice>
  <TJAuSellPrice>294.82</TJAuSellPrice>
  <TJAuBuyPrice>295.06</TJAuBuyPrice>
  <IsRemote>true</IsRemote>
</PreciousMetalConfigInfo>

------解决方案--------------------
DOMImplementation接口加载xml文档默认为异步执行。
火狐条件下你也设置一下xmlDoc.async = false;