Home > Web Front-end > JS Tutorial > Specific implementation of mutual acquisition of variables and element objects between parent element and child iframe_javascript skills

Specific implementation of mutual acquisition of variables and element objects between parent element and child iframe_javascript skills

WBOY
Release: 2016-05-16 17:19:52
Original
1581 people have browsed it

Parent:

Copy code The code is as follows:



var count = 1;


---- -------------------------------------------------- ------- In
sub-iframe:
Copy code The code is as follows:


alert(window.parent.count); //Get the js variable in the parent
alert($("#username", window.parent.document ));//Get the jQuery object in the parent
alert(window.parent.document.getElementByIdx_x('username'));//Get the DOM object in the parent


-------------------------------------------------- -------------------------------------------------- -

In child iframe (id="iframeId"name="iframeName"):
Copy code code As follows:



varcount = 1;


---------------------------------- --------------------------
Parent:
Copy code The code is as follows:


alert(document.iframeName.count);//Get the sub-iframe js variable
alert($(window.frames["iframeName"].document).contents().find("#username"));//Get the jQuery object in the sub-iframe
alert($(" #username",document.frames("iframeName").document));//Get the jQuery object in the sub-iframe
alert(window.document.getElementById('iframeId').contentWindow.document.getElementByIdx_x('username' ));//Get the DOM object in the child iframe


Collect some examples on the Internet:
Use jQuery to get the parent in the IFRAME The value
of a certain element in the window has to be realized by combining the DOM method and the jquery method

1. Select all the radio buttons in the IFRAME in the parent window
$(window. frames["iframe1"].document).find("input:radio").attr("checked","true");
2. Select all radio buttons in the parent window in IFRAME
$(window.parent.document).find("input:radio").attr("checked","true");
If the parent window wants to get the Iframe in the IFrame, just add a frames child. For example:
$(window.frames["iframe1"].frames["iframe2"].document).find("input:radio").attr("checked","true");
3. Call the method (FRAME) of another child window in the parent window in the child window:
parent.frames["Main"].Fun();
Note: It is recommended to use [] to compare like this Compatible with multiple browsers, ()Firefox/Sogou/Google are not compatible.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template