0
var bottomStack = function () {
                "use strict";
                ...
                jQuery('#bottomstacktitle', this.frame).bind('click', this.toggleFrame);
            };
            var = bottomStackExtends = {
                ...
                toggleFrame: function (animate) {
                    "use strict";
                    if (false !== animate) {
                        animate = true;
                    }
                    this.frame[((animate) ? 'animate' : 'css')]({bottom: (this.bottomStackClosed ?  -180 : 0)});
                    jQuery.cookie("bottomStackClosed", (!this.bottomStackClosed).toString());
                },...
            };

当它运行时,调试器会说:“未捕获的异常:TypeError:无法将'this.frame'转换为对象”。是的,因为这个“this”不是那个“this”,但是这个“this”是 jQuery('#bottomstacktitle', this.frame)。那么我可以合并到这个“this”,例如:.frame 标签吗?

我试过了:

var bottomstacktitle = jQuery('#bottomstacktitle', this.frame);
    bottomstacktitle.frame = this.frame;
    bottomstacktitle.bind('click', this.toggleFrame);

但不工作

你有什么解决办法吗?

谢谢!

4

1 回答 1

0

您可以使用 jQuery 检索最近的frame

var bottomStack = function () {
  "use strict";
   ...
   jQuery('#bottomstacktitle', this.frame).bind('click', this.toggleFrame);
};

var bottomStackExtends = {
  toggleFrame: function (animate) {
    "use strict";
    var currentFrame = jQuery(this).closest("frame").get(0);

    currentFrame[!!animate ? 'animate' : 'css']({
      bottom: this.bottomStackClosed ? -180 : 0
    });
    jQuery.cookie("bottomStackClosed", !this.bottomStackClosed));
  }
  // ...
};

jQuery 确保它this始终指向函数使用的元素。

click处理程序中,它将是接收到单击 ( '#bottomstacktitle') 的元素。由于该元素包含在您的框架中,您可以使用它.closest()来检索正确的框架对象。

于 2012-05-24T13:16:28.813 回答