简体   繁体   English

如何让jQuery引用一个新弹出的窗口?

[英]How to have jQuery refer to a newly popped up window?

In the django function showRelatedObjectLookupPopup, I'd like to bind a function to a button in the newly popped up window, but I don't know how to refer to the new window. 在django函数showRelatedObjectLookupPopup中,我想将函数绑定到新弹出的窗口中的按钮上,但是我不知道如何引用新窗口。 Here is what I have tried: 这是我尝试过的:

function showRelatedObjectLookupPopup(triggeringLink) {
// other function stuff omitted
    var name = triggeringLink.id.replace(/^lookup_/, '');
    name = id_to_windowname(name);
    var win = window.open(href, name, 500, 700, resizable=yes, scrollbars=yes');

    win.onload = function () {
         $(document).ready(function() {
               $("input.default").hover(function () {alert('hovered')})})};
    win.focus();
    return false;
}

But this binds to the button in the original window. 但这绑定到原始窗口中的按钮。

I think you are referring to the current window's document when you use 我认为您在使用时指的是当前窗口的文档

win.onload = function() { $(document).ready(...

try this: 尝试这个:

win.onload = function() { $(win.document).ready(...

and likewise, give a context to your input selector: 同样,为输入选择器提供上下文:

 $("input.default", win.document).hover(...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM