您的位置:首页 > Web前端 > JavaScript

JQ&&JS获取并操作iframe内容

2014-12-03 13:46 483 查看
Demo下载

获取iframe的document:

function iframeDom(id) {
return document.getElementById(id).contentDocument||document.frames[id].document;
}

jquery:

window.onload = function () {
var doc = iframeDom("my_iframe");
$(doc).find("#content").css("color","blue");
}

javascript:

window.onload = function () {
var doc = iframeDom("my_iframe");
doc.getElementById("content").style.color="blue";
}
index.html:

<iframe id="my_iframe" src="iframe.html"></iframe>

my_iframe.html:

<h1 id="content" style="color:red;">内容</h1>

注:

iframe刷新:

doc.location.reload();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: