• firefox并不支持selectSingleNode和selectNodes的解决方法


    转自:http://qsrock.iteye.com/blog/209585

     

    function test(){
    		var perid = document.thisForm.PerID.value;
    		
    		var xml="test";
    		 if(window.ActiveXObject){   
    	        var xml=new ActiveXObject("Microsoft.XMLDOM");
    			xml.async=false;
    			xml.load("xxxx.xml");
    			
    	        
    	    }else if((typeof document.implementation != 'undefined')&&
    	    	(typeof document.implementation.createDocument!='undefined')){   
    	        xml = document.implementation.createDocument("", "", null);
    
    			xml.async=false;
    			xml.load("xxxx.xml");
    
    			
    			//firefox并不支持selectSingleNode和selectNodes方法;下面两段是用XPath来解决firefox模拟selectSingleNode和selectNodes方法,正确性有待解决
    			XMLDocument.prototype.selectSingleNode = Element.prototype.selectSingleNode = function (xpath){
    		         var  x = this .selectNodes(xpath)
    		         if ( ! x || x.length < 1 ) return   null ;
    		         return  x[ 0 ];
    		    }
    			XMLDocument.prototype.selectNodes = Element.prototype.selectNodes = function (xpath){
    		         var  xpe  =   new  XPathEvaluator();
    		         var  nsResolver  =  xpe.createNSResolver( this .ownerDocument  ==   null   ?
    		             this .documentElement :  this .ownerDocument.documentElement);
    		         var  result  =  xpe.evaluate(xpath,  this , nsResolver,  0 ,  null );
    		         var  found  =  [];
    		         var  res;
    		         while  (res  =  result.iterateNext())
    		            found.push(res);
    		         return  found;
    		    }
    			
    			
    	    }  
    		//下面就可以用selectSingleNode和selectNodes方法
    		var row=null;
    	
    		if(perid.substring(0,5)=="NO" && perid.length==9){
    			row=xml.selectSingleNode("root/row[@ID='"+perid+"']");
    			if (row!=null){
    				document.thisForm.MenuColor.value=row.getAttribute("CssFileName");
    				ChangeBgColor(document.thisForm.MenuColor.value);
    			}
    		}
    	   
    	}
    

      

  • 相关阅读:
    那些容易忽略的事4-(正则表达式反向引用 )
    那些容易忽略的事3-(变量提升和函数提升)
    那些容易忽略的事(2)
    那些容易忽略的事(1) -变量与运算符+
    call()与apply()传参需要注意的一点
    CSS凹型导航按钮
    动态的99乘法表
    js中的for-of循环遍历数组
    交换2个变量的值
    gl.disableVertexArray P77 关闭location指定的attribute变量
  • 原文地址:https://www.cnblogs.com/xuqp/p/9446925.html
Copyright © 2020-2023  润新知