zoukankan      html  css  js  c++  java
  • 难道这就是JavaScript中的"闭包"

    其实对于JavaScript中的"闭包"还没真正理解,这次在实际Coding中似乎遇到了"闭包"的问题,仅此摘录,以待深究.

    表现为jQuery的post方法回调function内始终"拿"不到外部变量.

    将代码改写成如下模式,成功了.

    var reflesh = "Y";
    function onOk()
    {
         var pingZheng = document.getElementById("txtPinZhenNum").value;
         if (pingZheng == "")
         {
                    alert("凭证号为空");
                    document.getElementById("hdBtnExport").click();
                    return
         }
         var anchors = document.getElementById("DbList").getElementsByTagName("a");
                
         for (var i = 0; i < anchors.length; i++) {
              if (anchors[i].style.background == "yellow")
              {
                   var curr_asp_anchor = $(anchors[i]).prev()[0];
                   var id = anchors[i].attributes.getNamedItem("name").value;
                   $.post("CwNCExport.aspx", { getresult: "Y", id:id,pingZheng: pingZheng }, function (result) {
                            foo(curr_asp_anchor, result);
                        });
              }
         }
    }
    
    function foo(arr, result)
    {
        if (result == "Y") {
            arr.click();
            var tid = setInterval(function () {
                if (reflesh == "Y") {
                    window.location.href = window.location.href;
                    clearInterval(tid);
                }
                reflesh = "N";
            }, 3000);
        }
        else {
            alert("凭证号重复");
            document.getElementById("txtPinZhenNum").value = pingZheng;
            document.getElementById("hdBtnExport").click();
        }
    }
  • 相关阅读:
    cookie,请求报文,
    ser,ver
    关于 通知的 死循环,
    这读取的好蛋疼,为什么一写 一读就有问题了,不一致了,
    缓存小姐 挡拆,网络请求 不同步 惹的祸,
    viewdidload ,viewwillappear,
    提示输入 用户名 ,密码,--》转
    前端面试
    npm与cnpm
    vue与node和npm关系
  • 原文地址:https://www.cnblogs.com/zhuji/p/5824794.html
Copyright © 2011-2022 走看看