---
title: "jquery取得iframe元素的方法"
author: "yaofeng911"
date: "2009-12-19T22:42:23Z"
tags: ["HTML", "jQuery", "框架"]
categories: ["Web前端"]
slug: "jquery-iframe"
draft: false
lastmod: "2009-12-19T22:42:23Z"
id: 552133
url: "https://yaofeng911.iteye.com/blog/552133"
---

收集利用Jquery取得iframe中元素的几种方法 :

 

```
$(document.getElementById('iframeId').contentWindow.document.body).htm()
```

 

 显示iframe中body元素的内容。

 

```
$("#testId", document.frames("iframename").document).html();
```

 根据iframename取得其中ID为"testId"元素

 

```
$(window.frames["iframeName"].document).find("#testId").html()
```

 作用同上

 

收集网上的一些示例：

#### 用jQuery在IFRAME里取得父窗口的某个元素的值

只好用DOM方法与jquery方法结合的方式实现了

1.在父窗口中操作 选中IFRAME中的所有单选钮  
$(window.frames\["iframe1"].document).find("input\[@type='radio']").attr("checked","true");

2.在IFRAME中操作 选中父窗口中的所有单选钮  
$(window.parent.document).find("input\[@type='radio']").attr("checked","true");

iframe框架的：&lt;iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"&gt;&lt;/iframe&gt;

IE7中测试通过