---
title: "【转】Jquery修改iframe内容"
author: "wangyanlong0107"
date: "2018-12-19T04:24:37Z"
tags: []
categories: ["Web前端"]
slug: "jquery-iframe"
draft: false
lastmod: "2018-12-19T04:24:37Z"
id: 2435396
url: "https://bigdragon.iteye.com/blog/2435396"
---

query取得iframe中元素的几种方法

**在iframe子页面获取父页面元素**  
代码如下:

$('#objId', parent.document);  
// 搞定...

**在父页面 获取iframe子页面的元素**  
代码如下:

$("#objid",document.frames('iframename').document)

$(document.getElementById('iframeId').contentWindow.document.body).html()  
   
 显示iframe中body元素的内容。

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

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

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