0

我有以下代码:

     $(document).ready(function() {
       $("#popupClose").click(function(){  
            disablePopup();  
       });

       $(document).keypress(function(e){  
            if(e.keyCode==27) {  
                disablePopup();   
            }  
        });
}); 

现在(最终)可以在文档完成之前加载弹出窗口(需要弹出窗口来引导文件中的 PHP 流)。但是,由于这些函数仅在 document.ready 中创建,因此当我的脚本调用弹出窗口时,我的弹出窗口控件尚不可用。

帮助表示赞赏!

4

4 回答 4

2

您可能想尝试关于函数http://api.jquery.com/on/的 jQuery 文档

$(document).on('click', "#popupClose", function(e) {
  disablePopup();
});

或者

 $(document).on('keypress', "#popupClose", function(e) {
     if(e.keyCode == 27) { disablePopup(); }
    });
于 2012-08-09T12:08:19.337 回答
0

尝试使用.apply.calljavascript方法。这应该可以帮助您解决问题。.

于 2012-08-09T12:10:43.453 回答
0

Use "#popupClose" as a selector as it always assumes you're talking about an ID in the current document, not the parent. Apart from that- What context is jQuery being loaded from? The IFrame or the parent window? This can make a big difference. Check whether if you have added #popupClose after loading the DOM, you will need to rebind the elements to the DOM jQuery is using. That may be your issue.

于 2012-08-09T12:16:03.740 回答
0

只需尝试在 之外声明您的函数$(document).ready(function(){...}),就在

<script> </script>
于 2012-08-09T12:07:13.860 回答