zoukankan      html  css  js  c++  java
  • 20100709 问题

    下面这段代码我用 firebug 跟踪发现 87 行 handleFunc 函数中的this 居然是 window对象?

     _handleFunc.call(this); 不能正常运行,在 87 行 handleFunc 函数中 arguments 函数为空。

    为什么会是这样的呢? 

      1 <script type="text/javascript">
      2 
      3 
      4 var baseUrl = "http://g";
      5 
      6 var divObj = new Object();
      7 
      8 divObj.url = new Array();
      9 divObj.url.push("/index.php/Service/Salaallot");
     10 divObj.url.push("/index.php/Service/Salashelve");
     11 divObj.url.push("/index.php/Service/Sbch");
     12 divObj.url.push("/index.php/Service/Servicesend");
     13 divObj.url.push("/index.php/Service/Fault");
     14 
     15 divObj.name = new Array();
     16 divObj.name.push("Test1");
     17 divObj.name.push("Test2");
     18 divObj.name.push("Test3");
     19 divObj.name.push("Test4");
     20 divObj.name.push("Test5");
     21 
     22 
     23 //创建DIV,DIV1....DIV5
     24 var ajax = createAjax();
     25 ajax.url = [];
     26 ajax.divID = [];
     27 ajax.ajaxIDLength = divObj.url.length;
     28 for(var i=0;i<divObj.url.length;i++)
     29 {
     30     var bDiv = document.createElement("div");
     31     bDiv.setAttribute("id","div_" + i.toString());
     32     if(![-1,])
     33         bDiv.setAttribute("cssText","98%;height:15%;float:left;");
     34     else
     35         bDiv.setAttribute("style","98%;height:15%;float:left;");
     36     document.body.appendChild(bDiv);
     37     
     38     var tDiv = document.createElement("div");
     39     tDiv.setAttribute("id","div_" + i.toString() + "_t");
     40     if(![-1,])
     41         bDiv.setAttribute("cssText","100%;height:20%;float:left;");
     42     else
     43         bDiv.setAttribute("style","100%;height:20%;float:left;");    
     44     bDiv.appendChild(tDiv);
     45     tDiv.innerHTML = divObj.name[i];
     46     
     47     var fDiv = document.createElement("div");
     48     fDiv.setAttribute("id","div_" + i.toString() + "_f");
     49     if(![-1,])
     50         bDiv.setAttribute("cssText","98%;height:80%;float:left;");
     51     else
     52         bDiv.setAttribute("style","98%;height:80%;float:left;");    
     53     bDiv.appendChild(fDiv);    
     54     
     55     ajax.url.push( baseUrl + divObj.url[i] );
     56     ajax.divID.push( "div_" + i.toString() );
     57     
     58     ajaxExec.call(ajax,handleFunc);
     59     
     60 }
     61 
     62 
     63 var ajaxID = 0;
     64 function updateDiv()
     65 {
     66     //alert( ajax.divID );
     67     if (ajax.request.readyState == 4)
     68     {
     69         if(ajaxID===ajax.divID.length)
     70            return;
     71         if (ajax.request.status == 200)
     72         {
     73             document.getElementById(ajax.divID[ajaxID]).innerHTML = ajax.request.responseText;
     74             ajaxID = ajaxID + 1;
     75             ajax.request.open("GET", ajax.url[ajaxID], true);
     76             ajax.request.onreadystatechange = updateDiv;
     77             ajax.request.send(null);
     78             document.getElementById("test").innerHTML = document.getElementById("test").innerHTML + "----" + ajax.url[ajaxID];
     79         }
     80     }
     81     
     82     
     83     //ajaxQueue();
     84 }
     85 
     86 
     87 function handleFunc()
     88 {
     89     var ajaxObj = arguments[0];
     90     document.getElementById(ajaxObj.divID[ajaxObj.ajaxID]).innerHTML = ajaxObj.request.responseText;
     91 
    }
     92 
     93 
     94 //控制事件按顺序执行,托管
     95 function ajaxExec()
     96 {
     97     var _this = this;
     98     var _handleFunc = arguments[0];
     99     _handleFunc.prototype.ajaxObj = this;
    100     if (this.ajaxID===0)
    101     {
    102         this.request.open("GET"this.url[0], true);
    103         this.request.onreadystatechange = function(){
    104             _this.ajaxID = 1;
    105             ajaxExec.call(_this,_handleFunc);
    106         };
    107         this.request.send(null);
    108     }else{
    109         if (this.ajaxIDLength!=this.url.length)
    110             return;
    111         if (this.request.readyState == 4)
    112         {
    113             if (this.ajaxID===this.url.length)
    114                 return;
    115             if (this.request.status == 200)
    116             {
    117                 _handleFunc.call(this);
    118                 this.ajaxID = this.ajaxID + 1;
    119                 this.request.open("GET"this.url[this.ajaxID], true);
    120                 this.request.onreadystatechange = function(){
    121                     ajaxExec.call(_this,_handleFunc);
    122                 };
    123                 this.request.send(null);
    124             }
    125         }
    126         
    127     }
    128 }
    129 
    130 
    131 function createAjax()
    132 {
    133     var request ;
    134     try
    135     {
    136         request = new XMLHttpRequest();
    137     }catch(err){
    138         try
    139         {
    140             request = new ActiveXObject("Microsoft.XMLHTTP");
    141         }catch(error){
    142             request = new ActiveXObject("Msxml2.XMLHTTP");
    143         }    
    144     }
    145     if(!request)
    146     {
    147         alert("createAjax Error!");
    148     }else{
    149         this.request = request;
    150         this.ajaxID = 0;
    151         this.ajaxIDLength = 0;
    152         return this;    
    153     }
    154 }
    155 
    156 
    157 
    158 </script>


  • 相关阅读:
    判断字符串和null相等 if(keyword.equals("null"))
    去掉input text后面的叉
    设置标题小图标ico
    使用onclick跳转到其他页面。使用button跳转到指定url
    中文输入法不触发onkeyup事件的解决办法
    全选js实现
    修改数据库结构需要修改的部分
    1. 移动测试点
    2.7.2 元素定位:frame 内定位 driver.switch_to.frame()
    2.7.1 元素定位:selenium消息框处理 (alert、confirm、prompt)
  • 原文地址:https://www.cnblogs.com/chy1000/p/1774121.html
Copyright © 2011-2022 走看看