function bubble(content, triggerElm){
this.element = $('<div class="bubble" />').html(content);
this.element.css(.....) // here is positioned based on triggerElm
}
bubble.prototype.show = function(){
$(document).on('click', this._click.bind(this));
this.element.css(....)
};
bubble.prototype.hide = function(){
$(document).off('click', this._click.bind(this));
this.element.css(....)
};
bubble.prototype._click = function(event){
console.log('click', this);
if(this.element.is(event.target) || (this.element.has(event.target).length > 0))
return true;
this.hide();
};
var b = new bubble();
b.show();
b.hide();
我一直在控制台中看到点击事件(click),所以点击事件没有解绑。
但是如果我删除 bind()
调用,那么点击事件就会解绑。有谁知道为什么吗?我需要一种方法来能够在我的测试函数内更改“this”,这就是为什么我在使用 bind()
。
this.element
。你能展示一下它是在哪里引入的,以及click()
函数如何使用它吗?我相当确定我的示例可以适应它。 - JLRishethis.element
如何被使用吗? - JLRishe