Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/461.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-this.option在加载函数中变为未定义_Javascript_Jquery_Load_This - Fatal编程技术网

Javascript jQuery-this.option在加载函数中变为未定义

Javascript jQuery-this.option在加载函数中变为未定义,javascript,jquery,load,this,Javascript,Jquery,Load,This,我正在尝试稍微修改一个插件,这是原型函数,我已经标记了我添加的行 好的,我的问题发生在我添加的img load函数中。我用一段代码包围了旧代码,以确保脚本等待图像加载。 问题是,加载函数内部的“this”与外部的“this”没有连接。我试着给load函数一个参数,但显然它不起作用,或者我做错了什么 你知道一种简单的方式来继承“这个”吗?我真的不知道还能做什么 Plugin.prototype._fade = function(number) { var $element, currentSl

我正在尝试稍微修改一个插件,这是原型函数,我已经标记了我添加的行

好的,我的问题发生在我添加的img load函数中。我用一段代码包围了旧代码,以确保脚本等待图像加载。 问题是,加载函数内部的“this”与外部的“this”没有连接。我试着给load函数一个参数,但显然它不起作用,或者我做错了什么

你知道一种简单的方式来继承“这个”吗?我真的不知道还能做什么

Plugin.prototype._fade = function(number) {
  var $element, currentSlide, next, slidesControl, value,
    _this = this;
  $element = $(this.element);
  this.data = $.data(this);
  if (!this.data.animating && number !== this.data.current + 1) {
    $.data(this, "animating", true);
    currentSlide = this.data.current;
    if (number) {
      number = number - 1;
      value = number > currentSlide ? 1 : -1;
      next = number;
    } else {
      value = this.data.direction === "next" ? 1 : -1;
      next = currentSlide + value;
    }
    if (next === -1) {
      next = this.data.total - 1;
    }
    if (next === this.data.total) {
      next = 0;
    }

    this._setActive(next);
    slidesControl = $(".slidesjs-control", $element);



    var nxtImg = $(slidesControl.children(":eq(" + next + ")")).find("img:eq(0)"); // added
    if ( nxtImg.attr("longdesc") !== undefined ) {  // added
      nxtImg.attr("src", nxtImg.attr("longdesc")); // added
      nxtImg.removeAttr("longdesc"); // added
    } // added


    nxtImg.load(function(){ // added
      slidesControl.children(":eq(" + next + ")").css({
        display: "block",
        left: 0,
        zIndex: 0
      });
      this.options.callback.start(currentSlide + 1);
      if (this.options.effect.fade.crossfade) {
        return slidesControl.children(":eq(" + this.data.current + ")").stop().fadeOut(this.options.effect.fade.speed, (function() {
          slidesControl.children(":eq(" + next + ")").css({
            zIndex: 10
          });
          $.data(_this, "animating", false);
          $.data(_this, "current", next);
          return _this.options.callback.complete(next + 1);
        }));
      } else {
        slidesControl.children(":eq(" + next + ")").css({
          display: "none"
        });
        return slidesControl.children(":eq(" + currentSlide + ")").stop().fadeOut(this.options.effect.fade.speed, (function() {
          slidesControl.children(":eq(" + next + ")").stop().fadeIn(_this.options.effect.fade.speed).css({
            zIndex: 10
          });
          $.data(_this, "animating", false);
          $.data(_this, "current", next);
          return _this.options.callback.complete(next + 1);
        }));
      }
    }); // added



  }
};

您正在一个闭包变量“\u this”中捕获this。这不管用吗?

事实上你是对的!我刚刚用这个换了这个,现在一切都正常了。就这么简单,但我自己却想不出来。谢谢