zoukankan      html  css  js  c++  java
  • firefox chrome ie9,10,11 不支持selectSingleNode和selectNodes的解决方法

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

    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);   
                 }   
             }   
              
         }  
  • 相关阅读:
    docker 安装 mysql5.7
    docker 安装 redis
    docker 安装 gitlab
    docker 升级到新版本
    logstash 采集springboot 错误日志配置
    图片左下角添加水印
    frida动态修改
    反反frida调试
    IDA插件KeyPatch直接在IDA中修改arm指令
    frida调用制作dex(用于有些对象读取不了)
  • 原文地址:https://www.cnblogs.com/meetrice/p/3813266.html
Copyright © 2011-2022 走看看