我有一个父页main.php,内嵌一个iframe,该iframe指向iframe.htm页,我想在main.php页取得iframe里的表单控件值。
main.php内容如下:------------------------------------------------------------------------------------------------------
CODE:[Copy to clipboard]<?php 
echo        "父页面表单提交的\$textElem控件值为:".$textElem;
echo        "<br>";
echo        "iframe的input控件\$innerElem的值为:".$hiddenElem;
?>
<html>
<body>
<Script Language="JavaScript">
<!--
function check() {//将iframe内元素innerElem的值赋给主页面需提交Form内的隐藏元素
main_form.hiddenElem.value = frameElem.innerElem.value;
//alert("IFrame中文本框的值:" + document.main_form.hiddenElem.value);
}
//-->
</Script>
<form name="main_form" action="main.php" onsubmit="return check()">
<input type="text" name="textElem" value="主页面" id="textElem">
<input type="hidden" name="hiddenElem" id="hiddenElem">
<input type="submit">
</form>
<iframe src="iframe.htm" name="frameElem" id="frameElem" width="200" height="200" frameborder="1"></iframe>
</body>
</html> iframe.htm内容如下:------------------------------------------------------------------------------------------------------
CODE:[Copy to clipboard]<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>我是iframe<p>
<input type="text" name="innerElem" value="我是iframe里文本框innerElem的值">
</body>
</html>---------------------------------------------------------------------------------------------------------------------------------------
     我在IE中测试没有问题,在firefox中则拿不到iframe的input控件innerElem的值,上网查办天,知道是IE和Firefox的兼容性问题(有资料说在Firefox里要指定iframe的contentWindow属性,又有说“在Firefox中IFRAME的“document”不叫document,改名叫contentDocument, "window"改名叫contentWindow”),但是不知道怎么改,试了半天也不行,特请指教.

解决方案 »

  1.   

    frameElem.contentWindow.document.all.innerElem.value这样看看
      

  2.   

    还是不行,提示“frameElem.contentWindow.documen为空或不是对象”,我改成“main_form.hiddenElem.value = document.getElementById("frameElem").contentWindow.document.getElementById("innerElem").value;
    ”也只能在IE下正常拿到值,Firefox也不行,甚至我发现我有一个从网上找的正则表单验证js也不能在Firefox下正常使用,IE下会提示用户什么什么不能为空之类的,Firefox直接就过去了,什么提示也没有。这问题头疼两天了,找了N多资料,在php国际喜悦村也发帖问来着,没人能回答。