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

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

WBOY
WBOYOriginal
2016-06-24 11:20:561175browse

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

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

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

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

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

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

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

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

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

parent.myFunction();

注意事项:

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

觉得不错,赞助我:

Statement:
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