JavaScript获取iframe中form表单中元素的值


index.html内容:

<iframe id="mpage" name="mpage" onload="AdaptorHeight()" style="border-style: none; height: 100%;width: 100%;"
scrolling="auto" frameborder="0" src="test.html">


test.html内容:

<form name="f1" id="f1" action="" method="post"> 
   <input name="uid" id="uid" type="text" value="input" /> 
</from>

方法一:通过ID获取

var name =  parent.document.getElementById("mpage").contentWindow.document.getElementById('uid').value;

方法二:通过Form获取

var name1 =  parent.document.getElementById("mpage").contentWindow.document.forms['f1'].uid.value;





本文出自 “IT技术学习与交流” 博客,谢绝转载!

你可能感兴趣的:(JavaScript)