Get the value of an element of the parent window in the IFRAME with jQuery DOM method and jquery method to combine the way to achieve
**1. In the parent window, select all radio buttons in the IFRAME **$(window frames [r]. “iframe1” document), find (” input [@ type = ‘radio’] ”). Attr (” checked ”, “true”);
**2. Operate all the radio buttons in the selected parent window in the IFRAME **$(window. The parent. The 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 passed the test
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>jQuery control iframe</title>
<script type="text/ecmascript" src="../js/jquery-1.2.6.js"></script>
<script type="text/javascript">
$(function(){
$("#t1").hover(function(){alert('');});
//$("iframe").contents().find("body").append("I'm in an iframe!");
//$(window.frames["iframe1"].document).find("input[@type='text']").attr("size","30px");
//$("#iframe1").contents().find("#d1").css('color','red');
//$(window.frames["iframe1"].document).find("input[@name='t1']").css({background:"#369"});
//$("#iframe1").src("test.html");
});
</script>
</head>
<body>
<div>
<input type="text" id="t1" />
<iframe id="iframe1" src="child.htm"></iframe>
<iframe src="child.htm" width="300" height="100"></iframe>
</div>
<div>
</div>
</body>
</html>
Use jquery to manipulate the iframe
There are two ifame in the content
< The iframe id = “leftiframe”… < / iframe> < The iframe id = “mainiframe.. < / iframe>
JQuery in leftiframe changes the SRC code of mainiframe: $(” # mainframe ”, the parent. The document. The body). Attr (” SRC ”, ”/ / www.jb51.net”)
**2. If the content contains an ifame with the ID mainiframe **< The iframe id = “mainifame”… > < / ifame> Ifame contains a someID < Div id = “someID” > You want to get this content< / div> Get the content of someID
$(” # mainiframe ”). The contents (.), find (” someID ”). The HTML () HTML or $(” # mainiframe ”). The contains (). The find (” someID ”). The text () value
3. In the parent window, select all radio buttons in the IFRAME $(window frames [r]. “iframe1” document), find (” input [@ type = ‘radio’] ”). The attr (” checked ”, “true”);
The natural choice for id is to still use the find method $(window frames [r]. “iframe1” document), find (” # id ”)