现在的位置: 首页 > 综合 > 正文

jQuery控制iFrame

2012年04月26日 ⁄ 综合 ⁄ 共 1544字 ⁄ 字号 评论关闭

 研究半天没有成功,保存再研究。参考:
http://hi.baidu.com/hankx/blog/item/5d4f4e08a85370920a7b82c8.html
http://www.cnblogs.com/Terrylee/archive/2007/12/09/the-ultimate-jquery-plugin-list.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框架的:

<iframe src=”test.html” id=”iframe1″ width=”700″ height=”300″ frameborder=”0″ scrolling=”auto”></iframe>

IE7中测试通过

代码:

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" >
  3. <head>
  4.     <title>jQuery控制iframe</title>
  5.     <script type="text/ecmascript" src="../js/jquery-1.2.6.js"></script>
  6.     <script type="text/javascript">
  7.         $(function(){
  8.             $("#t1").hover(function(){alert('');});
  9.             //$("iframe").contents().find("body").append("I'm in an iframe!"); 
  10.             //$(window.frames["iframe1"].document).find("input[@type='text']").attr("size","30px");
  11.             //$("#iframe1").contents().find("#d1").css('color','red');
  12.             //$(window.frames["iframe1"].document).find("input[@name='t1']").css({background:"#369"});
  13.             //$("#iframe1").src("test.html");
  14.         });
  15.     </script>
  16. </head>
  17. <body>
  18. <div>
  19. <input type="text" id="t1" />
  20. <iframe id="iframe1" src="child.htm"></iframe>
  21. <iframe src="child.htm" width="300" height="100"></iframe>
  22. </div>
  23. <div>
  24. </div>
  25. </body>
  26. </html>

end

抱歉!评论已关闭.