English 中文(简体)
合并到此 jQuery
原标题:Merge to this jQuery
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: 无法将此. 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);

但不工作

你有什么解决办法吗?

谢谢!

问题回答

您可以使用 jQuery 获取最接近 < code > frame 的 < code > :

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 总是指向函数使用的元素 。

点击 处理器中, 将会是被点击的元素 ( # bottomstack标题 )。 由于此元素包含在您的框架, 您可以使用 . closest () 获取右框架对象 。





相关问题
"this" keyword in IE

So, I using this snippet <tr onclick="this.toggleClassName( selected )"> on a web page. (a Prototype.js function) It works great. All I do is click on a table row, and it appears to get ...

Accessing an outer class from inside a listener?

I have a listener inside Class A, and I want to pass Class A to my Class B inside the listener. Normally I d just use this, but then I d get the event that triggered the listener.

this, current context-when should I use in jQuery?

I am not very sure with the use of "this" [current context] in jquery.What I know is- it prevents the dom from searching all the elements, it just work on that current element, which improve ...

Why is this not updating to refer to a new object?

I m writing an online game which allows a user to progress from one puzzle to the next, and if the user makes mistakes, each puzzle has a start again button to allow the user to start just that puzzle ...

Should the RequireThis check in Checkstyle be enabled?

One of the built-in Checkstyle checks is RequireThis, which will go off whenever you don t prepend this. to local field or method invocations. For example, public final class ExampleClass { ...

热门标签