请问怎么去除这个可恶的弹窗呀

这个弹窗怎么去除哇??删除什么代码可以去除~删除什么代码.可以去除~删除什么代码可.以去除~

img

img

  • 这有个类似的问题, 你可以参考下: https://ask.csdn.net/questions/7657466
  • 这篇博客你也可以参考下:函数就是封装了一段可以被重复执行调用的代码块 目的: 就是让大量代码重复使用
  • 除此之外, 这篇博客: 在函数内部修改变量后,为什么变量未更改? -异步代码参考中的 部分也许能够解决你的问题, 你可以仔细阅读以下内容或跳转源博客中阅读:
  • You might currently have some code similar to this; 您当前可能有一些与此类似的代码;

    function getWidthOfImage(src) {
        var outerScopeVar;
    
        var img = document.createElement('img');
        img.onload = function() {
            outerScopeVar = this.width;
        };
        img.src = src;
        return outerScopeVar;
    }
    
    var width = getWidthOfImage('lolcat.png');
    alert(width);
    

    However, we now know that the return outerScopeVar happens immediately; 但是,我们现在知道return outerScopeVar立即发生。 before the onload callback function has updated the variable. onload回调函数更新变量之前。 This leads to getWidthOfImage() returning undefined , and undefined being alerted. 这将导致getWidthOfImage()返回undefined ,并且将向undefined发出警报。

    To fix this, we need to allow the function calling getWidthOfImage() to register a callback, then move the alert'ing of the width to be within that callback; 为了解决这个问题,我们需要允许调用getWidthOfImage()的函数注册一个回调,然后将宽度的警报移到该回调内;

    function getWidthOfImage(src, cb) {     
        var img = document.createElement('img');
        img.onload = function() {
            cb(this.width);
        };
        img.src = src;
    }
    
    getWidthOfImage('lolcat.png', function (width) {
        alert(width);
    });
    

    ... as before, note that we've been able to remove the global variables (in this case width ). ...与以前一样,请注意,我们已经能够删除全局变量(在本例中为width )。


  • 您还可以看一下 李宁老师的征服微信小程序视频教程课程中的 编写猜拳游戏的业务逻辑代码小节, 巩固相关知识点