【问题标题】:How to popup a dialog in another frame using jquery-ui如何使用 jquery-ui 在另一个框架中弹出对话框
【发布时间】:2011-05-13 17:22:48
【问题描述】:

我正在使用 jquery-ui-1.8 创建一个小型网页,该网页具有一个框架集和三个框架。

<frameset id="mainFrame"cols="25%,*,25%"> 
    <frame  id="f1" src="test.php"></frame> 
    <frame id="f2" src="test2.php"/>
    <frame  />
</frameset>

然后我在 test.php 文件中添加了一个按钮,该文件在第一帧 (f1) 加载,并为 test2.php 添加了一个 div,它在第二帧加载。

<div id="testdiv"> this is test 2</div>

然后,当我单击 f1 中的按钮时,我需要在第二帧 (f2) 上的“testdiv”中弹出一个 jquery 对话框。

我尝试了这些线程中给出的解决方案。 [1] - Display jquery dialog in parent window

var $jParent = window.parent.jQuery.noConflict();
var dlg1 = $jParent('#testdiv');
dlg1.dialog();

和 [2] - jQuery UI dialog display inside frame, from bookmarklet?

var frame = window.frames[1];
var div = $(frame.document.getElementById("testdiv"));
div.html("My popup contents");
div.dialog();

但这些都不会在第二帧内弹出对话框。有人可以帮我解决这个问题。

【问题讨论】:

    标签: jquery dialog jquery-ui-dialog


    【解决方案1】:

    只用这种方式进行测试,也许这不是最好的方式,但你可以试试。 (注意:不要忘记在 iframe f2 上添加属性 -> name="f2"

    在test.php中:

    <button onclick="parent.f2.$('#testdiv').dialog('open');">test</button>
    

    在 test2.php 中:

    <link type="text/css" href="jquery-ui.css" />
    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery-ui.js"></script>
    <script type="text/javascript">
    $(function() {
       $( "#testdiv" ).dialog({
        autoOpen: false
       });
    });
    </script>
    
    <div id="testdiv"> hello world! </div>
    

    【讨论】:

    • 感谢 bungdito,它运行良好,您节省了我很多时间。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-10
    相关资源
    最近更新 更多