Javascript这在子窗口的就绪回调中给出了错误的值

Javascript这在子窗口的就绪回调中给出了错误的值,javascript,popup,this,Javascript,Popup,This,这个答案表明,当在JQuery回调中使用“This”对象时,它将引用要添加回调的所选元素。但是,在设置子窗口的就绪回调时,这似乎不起作用: var new_window = window.open('./NewWindow.aspx', '_blank'); $(new_window.document).ready(function () { console.dir(this); }); 在上面的示例中,这显然是父窗口的文档,而不是“NewWindow”文档。文档中正在发生“ready

这个答案表明,当在JQuery回调中使用“This”对象时,它将引用要添加回调的所选元素。但是,在设置子窗口的就绪回调时,这似乎不起作用:

var new_window = window.open('./NewWindow.aspx', '_blank');
$(new_window.document).ready(function () {
    console.dir(this);
});

在上面的示例中,这显然是父窗口的文档,而不是“NewWindow”文档。

文档中正在发生“ready”事件

如果要在事件处理程序中使用不同的内容覆盖
,则必须
绑定不同的上下文:

var new_window = window.open('./NewWindow.aspx', '_blank');
$(new_window.document).ready(function () {
    console.dir(this);
}.bind(new_window));

更多详细信息

文档中正在发生“就绪”事件

如果要在事件处理程序中使用不同的内容覆盖
,则必须
绑定不同的上下文:

var new_window = window.open('./NewWindow.aspx', '_blank');
$(new_window.document).ready(function () {
    console.dir(this);
}.bind(new_window));
更多细节