从父窗口的子窗口中的JQuery运行功能 [英] Jquery run function from child window in parent window

查看:88
本文介绍了从父窗口的子窗口中的JQuery运行功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个弹出窗口,我想在父窗口中运行一个函数.

I have a popup window and I want to run a function from in the parent window.

我的孩子有:

$(document).ready(function(){
    parent.$.fn.guestFromPop('Action');
});

在父母中,我有:

$(document).ready(function(){
    function guestFromPop(data) {
        alert(data);
    }
});

问题是当parent.$.fn.guestFromPop('Action');我从没看到警报时,什么也没发生.我在做错什么吗?

The problem is when parent.$.fn.guestFromPop('Action'); I never see the alert, nothing happens. Am I doing something wrong?

推荐答案

这未声明函数$.fn.guestFromPop:

$(document).ready(function(){
  function guestFromPop(data) {
    alert(data);
  }
});

...它所做的只是声明guestFromPop(),该函数仅在该document.ready处理程序内部可用.您需要改为声明要使用的函数:

...all it does is declare guestFromPop(), a function only available inside that document.ready handler. You would need to declare the function you're after instead:

$.fn.guestFromPop = function(data) {
  alert(data);
};

尽管如此,但这也不是正确的,因为它不会在jQuery元素上调用,所以您可能想要简单的东西:

Though, this isn't really correct either, since it wont be called on a jQuery element, you may want something as simple as :

function guestFromPop(data) {
  alert(data);
}

呼叫者:

parent.guestFromPop('Action');

这篇关于从父窗口的子窗口中的JQuery运行功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆