如何使用jquery-ui在另一个框架中弹出一个对话框 [英] How to popup a dialog in another frame using jquery-ui
问题描述
我正在使用jquery-ui-1.8创建一个小型网页,它具有一个框架集和三个框架。
I'm creating a small web page using jquery-ui-1.8 which is having a frameset and three frames.
<frameset id="mainFrame"cols="25%,*,25%">
<frame id="f1" src="test.php"></frame>
<frame id="f2" src="test2.php"/>
<frame />
</frameset>
然后我添加了一个按钮到第一帧(f1)加载的test.php文件和一个到第二个框架加载的test2.php的div。
Then I have added a button to test.php file which is loaded at the first frame (f1) and a div to test2.php which is loaded at the second frame.
<div id="testdiv"> this is test 2</div>
然后我需要在第二帧(f2)上弹出一个testdiv的jquery对话框我点击f1中的按钮。
Then I need to pop up a jquery dialog from "testdiv" on the second frame (f2) when I click on the button in the f1.
我尝试过在这些线程中给出的以下解决方案。
[1] - 在父窗口中显示jQuery对话框
I tried following solutions given at these threads. [1] - Display jquery dialog in parent window
var $jParent = window.parent.jQuery.noConflict();
var dlg1 = $jParent('#testdiv');
dlg1.dialog();
和
[2] - jQuery UI对话框显示在框架内,从bookmarklet?
var frame = window.frames[1];
var div = $(frame.document.getElementById("testdiv"));
div.html("My popup contents");
div.dialog();
但是没有这些弹出窗口第二帧中的对话框。有人可以帮我解决这个问题。
But non of these pop ups the dialog within the second frame. Can some one please help me to solve this problem.
推荐答案
只是为了这样做测试,也许这不是最好的方法,但你可以尝试。
(注意:不要忘记添加属性 - > name =f2< - on iframe f2)
just make test for this way, maybe this is not the best way but you can try it. (Attention: don't forget to add the attribute -> name="f2" <- on iframe f2)
in test.php: / p>
in test.php:
<button onclick="parent.f2.$('#testdiv').dialog('open');">test</button>
in test2.php:
in 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>
这篇关于如何使用jquery-ui在另一个框架中弹出一个对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!