繁体   English   中英

jQuery帧间通信

[英]Jquery Inter-Frame Communication

我有main_page.htm作为

<frameset rows="30,*" frameborder=0 border=0>
       <frame name="top_frame" src="top.htm">
       <frame name="bottom_frame" src="bottom.htm">
</frameset>

bottom.htm中的代码是:

<div id="BottomFrameTest">Hi There!</div>

现在如何更改top_frame中位于top.htm中的文本

top.htm中的代码是:

<script>
   function ChnageDivText()
   {
      $("#BottomFrameTest").html("Hello World. This text is changed");
   }
</script>
<body>
   <input type="button" value="Change Text" onclick="ChnageDivText()" />
</body>

上面的代码显然不起作用。 如何与top_frame bottom_frame通信?

假设所有框架都来自可以使用的同一个域

 parent.bottom_frame.getElementById("BottomFrameTest").innerHTML = "Hello World. This text is changed";

当然,如果您真的想使用jquery,则可以执行

 $(parent.bottom_frame).find("#BottomFrameTest").html("Hello World. This text is changed");

您可以尝试执行类似的操作,实际上您正在尝试更新其他框架的元素,因此您尝试进行跨框架jquery操作

$(document).ready(function(){
    function ChnageDivText()
       {
          $(parent.BottomFrameTest.document).contents().find(‘#TextBox1′).val(‘Hello World. This text is changed’);
       }

});

例如,我已经使用文本框,可以在find方法中设置所需元素的ID。 您可以在这里更深入地找到它。

如果$.contents()对您来说是新的,则可以在此处找到它。

是一个来自jQuery文档的类似示例。

希望所有人都能对您有所帮助。

暂无
暂无

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

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