Use jQuery to obtain the value of an element in the parent window in IFRAME.
We had to use the DOM method and jquery method to achieve this.
1. In the parent window, select all radio buttons in IFRAME.
$ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
2. in IFRAME, select all radio buttons in the parent window
Vertex (w.w.parent.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
Iframe framework:
<Iframe src00000000test.html "id =" iframe1 "width =" 700 "height =" 300 "frameborder =" 0 "scrolling =" auto "> </iframe>
IE7 passed the test
Code:
Copy codeThe Code is as follows:
<! 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 controls 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" 2.16.doc ument ). find ("input [@ type = 'text']"). attr ("size", "30px ");
// $ ("# Iframe1"). contents (). find ("# d1" ).css ('color', 'red ');
// $ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ name = 't1']" cmd.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 operate iframe
1. The content contains two ifame
<Iframe id = "leftiframe"... </iframe>
<Iframe id = "mainiframe... </iframe>
In leftiframe, jQuery changes the src code of mainiframe:
$ ("# Mainframe", parent.doc ument. body). attr ("src", "http://www.jb51.net ")
2. If the content contains an ifame with the ID of mainiframe
<Iframe id = "mainifame"...> </ifame>
Ifame contains a someID
<Div id = "someID"> you want to get this content </div>
Get someID content
$ ("# Mainiframe "). contents (). find ("someID" ).html () html or $ ("# mainiframe "). contains (). find ("someID "). text () Value
3. In the parent window, select all radio buttons in IFRAME.
$ (Window. frames ["iframe1" cmd.doc ument). find ("input [@ type = 'Radio ']"). attr ("checked", "true ");
Then the find method is still used to select the id.
$ (Window. frames ["iframe1" cmd.doc ument). find ("# id ")