我正在创建一个编辑下拉菜单,并使用以下代码来捕捉菜单外的点击。在菜单外单击应该会触发close函数。注意:这是在mvc结构的应用中使用的。
在我们到达IE8之前,一切都是正常的,它显示"object不支持属性或方法“。他们有没有其他方法来创建这个绑定呢?
var that = this
$("body").on('click', that.outsideClickWatch.bind(that) );
outsideClickWatch:function(e){
console.log("addOutsideClickWatch", this)
this.remove()
}
发布于 2014-11-05 11:00:37
哈哈,我设法找到了我自己的答案:)我用了下面的方法,一切都很好。不过还是要感谢Frederic的回复。
$(document).delegate('body', 'click', function(e) { that.outsideClickWatch(e) });
https://stackoverflow.com/questions/26755274
复制