Home > Web Front-end > HTML Tutorial > jquery操作iframe中的元素和js函数_html/css_WEB-ITnose

jquery操作iframe中的元素和js函数_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:20:56
Original
1290 people have browsed it

1、jquery操作iframe中的元素(2种方式)

var str = $(window.frames["iframe"].document).find("#ljiong").html(); var stk = $("#iframe").contents().find("#ljiong").html();
Copy after login

2、操作父界面中的元素(header:为某个元素的id)

$('#header', parent.document).text();window.parent.$("#header").text();
Copy after login

3、js调用iframe中的js函数(2种)

window.frames["ljiong"].window.testIframe2("ljiong"); document.getElementById("ljiong").contentWindow.testIframe2("ljiong");
Copy after login

4、jquery调用iframe的js函数(带参数的会有返回值)

$("#ljiong")[0].contentWindow.testIframe2("ljiong");
Copy after login

5. 调用父页面js函数,直接用:

parent.myFunction();
Copy after login

注意事项:

1、要和所包含的iframe在同一个域名(因为不能跨域)

觉得不错,赞助我:

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