沫沫金:实践使用的jQuery获取框架内容的方法

简介: 沫沫金亲自验证,支持IE6    沫沫金分享利用Jquery取得iframe中元素的几种方法 : document.getElementById方式:Js代码   $(document.getElementById('iframeId').contentWindow.document.body).htm()   $(document.getElementById('iframeId').contentWindow.document.body).htm()  显示iframe中body元素的内容。

沫沫金亲自验证,支持IE6 

 

沫沫金分享利用Jquery取得iframe中元素的几种方法 :

document.getElementById方式: Js代码  
  1. $(document.getElementById('iframeId').contentWindow.document.body).htm()  
$(document.getElementById('iframeId').contentWindow.document.body).htm()

 显示iframe中body元素的内容。

jQuery双参数法:Js代码   
  1. $("#testId", document.frames("iframename").document).html();  
$("#testId", document.frames("iframename").document).html();

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

jQuery的find方法获取法:Js代码   
  1. $(window.frames["iframeName"].document).find("#testId").html()  
$(window.frames["iframeName"].document).find("#testId").html()

 

2012卖的最好的粽子

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

只好用DOM方法与jquery方法结合的方式实现了,dom很强大的

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框架的:<iframe src="test.html" id="iframe1" width="700" height="300" frameborder="0" scrolling="auto"></iframe>
 
 
目录
相关文章
|
4天前
|
JavaScript CDN
jQuery方法小记
jQuery方法小记
21 0
|
4天前
|
JavaScript
jQuery追加节点方法 和height方法与width方法
jQuery追加节点方法 和height方法与width方法
|
4天前
|
JavaScript 前端开发
调用jQuery的animate()方法无法移动的问题
调用jQuery的animate()方法无法移动的问题
|
4天前
|
JavaScript 前端开发 UED
jQuery 自动刷新页面但不闪烁的实现方法
jQuery 自动刷新页面但不闪烁的实现方法
|
4天前
|
Java 数据库 数据安全/隐私保护
基于SSM框架实现管科类考研自我管理系统(分前后台spring+springmvc+mybatis+maven+jsp+jquery)
基于SSM框架实现管科类考研自我管理系统(分前后台spring+springmvc+mybatis+maven+jsp+jquery)
|
4天前
|
JavaScript Serverless
jquery attr()方法
jquery attr()方法
16 0
|
2天前
|
JavaScript 索引
|
4天前
|
JavaScript
jquery获取子元素的一些方法
jquery获取子元素的一些方法
9 0
|
4天前
|
JavaScript 前端开发 API
jquery的一些方法
jquery的一些方法
7 1
|
4天前
|
JavaScript
jquery获取子元素的一些方法
jquery获取子元素的一些方法