---
title: "获取iframe中的form"
author: "robbln"
date: "2013-11-05T15:47:19Z"
tags: []
categories: ["Web前端"]
slug: "iframe-form"
draft: false
lastmod: "2013-11-05T15:47:19Z"
id: 1971298
url: "https://robbln.iteye.com/blog/1971298"
---

DOM获取页面中的iframe:

`1` `window.frames["iframeChild"].document    //假如iframe的id为iframeChild`

`2` `window.parent.document    //在子窗口中操作父窗口`

获取页面的对象其实就是DOM方法外面加上jquery的选择符：

[view source](http://www.vipaq.com/index.php/Detail/view/item/134#viewSource "view source")[print](http://www.vipaq.com/index.php/Detail/view/item/134#printSource "print")[?](http://www.vipaq.com/index.php/Detail/view/item/134#about "?")

`1` `$(window.frames["iframeChild"].document)    //假如iframe的id为iframeChild`

`2` `$(window.parent.document)    //在子窗口中操作父窗口`

接下来就可以继续获取iframe内的DOM了，获取iframe内的dom对象有两种方法：

`1` `$(window.frames["iframeChild"].document).find("#child")    //第一种`

`2` `$("#child",window.frames["iframeChild"].document)    //第二种`

1.在父窗口中操作 选中IFRAME中的所有单选按钮

`1` `$(window.frames["iframeChild"].document).find("input[@type='radio']").attr("checked","true");`

2.在IFRAME中操作 选中父窗口中的所有单选按钮

`1` `$(window.parent.document).find("input[@type='radio']").attr("checked","true");`

在父页面提交iframe中的表单

 frames\["iframe"].document.forms\["form1"].action="${base}/comSub.jspx";

 frames\["iframe"].document.forms\["form1"].submit();