This article mainly analyzes and introduces iframe operations in jquery in detail. If you need help, please refer to them.
Use jquery to operate iframe
1. The content contains two ifame
In leftiframe, jQuery changes the src code of mainiframe:
$ ("# Mainframe", parent.doc ument. body). attr ("src", "http://www.radys.cn ")
2. If the content contains an ifame with the ID of mainiframe
</Ifame> <BR> ifame contains a someID <BR> <p id = "someID"> you want to get this content </p> <BR> get someID content </P> <P> $ ("# mainiframe "). contents (). find ("someID" ).html () html or $ ("# mainiframe "). contains (). find ("someID "). text () value </P> <STRONG> 3. In the parent window, select all radio buttons in IFRAME. <BR> </STRONG> $ (window. frames ["iframe1" 2.16.doc ument ). find ("input [@ type = 'Radio ']"). attr ("checked", "true"); </P> <P> you can still use the find method to select an id. <BR> $ (window. frames ["Iframe1" 2.16.doc ument ). find ("# id ") </P> <STRONG> 4. Content of someID in the jQuery operation mainiframe in leftiframe <BR> $ ("# mainframe ", parent.doc ument. body ). contents (). find ("someID" ).html () or $ ("# mainframe", parent.doc ument. body ). contents (). find ("someID "). val () </P> <P> using JavaScript to manipulate iframe </P> <STRONG> mutual reference between frames </STRONG> </P> <P> all frameworks are provided as properties of window objects in the form of collections, example: window. frames indicates the set of all frames on the page. Similar to object, image object, etc. The difference is that these sets are the attributes of document. Therefore, to reference a sub-framework, you can use the following syntax: </P> <P> window. frames ["frameName"]; </P> <P> window. frames. frameName </P> <P> window. frames [index] </P> <P> the window can also be replaced or omitted with self. If frameName is the first frame on the page, the following statements are equivalent: </P> <P> self. frames ["frameName"] </P> <P> self. frames [0] </P> <P> frames [0] </P> <P> frameName </P> <P> each frame corresponds to an HTML page, therefore, this framework is also an independent browser window, which has all the properties of the window. The so-called reference to the framework is the reference to the window object. With this windowless object, you can easily perform operations on the page. For example, you can use the volume upload Doc ument object to write data to the page, and use the window. location attribute to change pages in the framework. </P> <P> The following describes the mutual references between frameworks of different levels: </P> <STRONG> 1. references from the parent framework to the Child Framework </STRONG> </P> <P> after understanding the above principles, it is very easy to reference the child framework from the parent framework, that is: </P> <P> window. frames ["frameName"]; </P> <P> references the sub-framework named frameName on the page. If you want to reference the sub-framework in the sub-framework, the referenced framework is actually the nature of the window object, which can be implemented as follows: </P> <P> window. frames ["frameName"]. frames ["frameName2"]; </P> <P> in this way, the second-level sub-framework can be referenced, and so on. </P> <STRONG> 2. references from the Child Framework to the parent framework </STRONG> </P> <P> each window object has a parent attribute, indicating its parent framework. If the framework is already a top-level framework, window. parent also indicates the framework itself. </P> <STRONG> 3. reference between sibling frameworks </STRONG> </P> <P> If the two frameworks share the same child framework, they are called sibling frameworks, and mutual reference can be achieved through the parent framework, for example, a page contains two sub-frameworks: </P> <frameset rows = "50%, 50% "> </P> <frame src =" 1.html "name =" frame1 "/> </P> <frame src =" 2.html "name = "frame2"/> </P> </frameset> </P> <P> In frame1, you can use the following statement to reference frame2: </P> <P> self. parent. frames ["frame2"]; </P> <STRONG> 4. mutual reference between frameworks of Different Levels </STRONG> </P> <P> the framework layers are for top-level frameworks. When the layers are different, you only need to know your own layers and the layers and names of another framework, and use the window object properties referenced by the Framework to easily implement mutual access. For example: </P> <P> self. parent. frames ["childName"]. frames ["targetFrameName"]; </P> <STRONG> 5. the reference to the top-level framework </STRONG> </P> <P> is similar to the parent attribute. The window object also has a top attribute. It indicates a reference to the top-level framework, which can be used to determine whether a framework itself is a top-level framework. For example: </P> <P> // determine whether the framework is a top-level framework </P> <P> if (self = top) {</P> <P> // dosomething </P> <P>}