从父窗口获取iframe中文本框的值

rak*_*aki 10 html javascript iframe jquery

我的页面中有一个iframe,如何在单击按钮的情况下从父页面获取框架中t文本框的值?

这是我的代码

<div>
<iframe src="test.html" >
<input type=text id="parent_text">
<input type="button">
</div>
Run Code Online (Sandbox Code Playgroud)

这是d test.html

<input type="text" id="frame_text">
Run Code Online (Sandbox Code Playgroud)

谢谢

小智 11

像这样的东西:

var iframe = document.getElementById('iframeId');
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
var input = innerDoc.getElementById('frame_text');
Run Code Online (Sandbox Code Playgroud)

首先你得到iframe.然后从iframe中获取第一个有效的dom文档.

并最终得到输入框.