本文实例讲述了JS实现向iframe中表单传值的方法。分享给大家供大家参考,具体如下:给ifra
本文实例讲述了JS实现向iframe中表单传值的方法。分享给大家供大家参考,具体如下:
给iframe加contentWindow属性后,才能赋值,在IE,firefox测试一切ok.
例如:
页面a.jsp
<script language="JavaScript">
function ExecuteSql()
{
var FormObj = document.getElementById("ResultShowFrame").contentWindow;
var SqlStr=document.getElementById("sqlcontent").value;
if (SqlStr !="")
{
FormObj.document.getElementById("Sql").value=SqlStr;
FormObj.document.getElementById("Result").value='Submit';
FormObj.document.ExecuteForm.submit();
}
}
</script>
<form name="dbcompress" action="?Action=CompressDate" method="post">
<textarea name="sqlcontent" rows="3" wrap="OFF" style="width:100%;" id="sqlcontent"></textarea>
<input name="Submit" type="button" onClick="ExecuteSql();" class="Anbut2" value=" 执 行 ">
</form>
<iframe id="ResultShowFrame" scrolling="yes" src="b.asp" style="width:100%;height:420;" frameborder=1></iframe>
页面b.jsp:
<form name="ExecuteForm" method="post" action="">
<input type="hidden" name="Sql" id="Sql">
<input type="hidden" name="Result" id="Result">
</form>
JS
iframe
表单传值