Winter2018-06-21
在父文档中定义的样式不会对iframe中的元素起作用。
方法一:
直接通过设置backgroundColor的颜色即可: <!DOCTYPE html> <html> <head> <script> function changeStyle() { var x=document.getElementById("myframe"); var y=(x.contentWindow || x.contentDocument); if (y.document)y=y.document; y.body.style.backgroundColor="#0000ff"; } </script> </head> <body> <iframe id="myframe" src="demo_iframe.htm"> <p>Your browser does not support iframes.</p> </iframe> <br><br> <input type="button" onclick="changeStyle()" value="Change background color"> </body> </html> 方法二:
<script>
<
script
>
function hideImg(i) {
var imgs = i.contentWindow.document.getElementsByTagName('img');
for(var i=0;i<imgs.length;i++)imgs[i].style.display='none'
for(var i=0;i<
imgs.length
;i++)imgs[i]
.style.display
=
'none'
}
</script>
<iframe onload="hideImg(this)"
Newest Answer
方法一:
<
script
>
function hideImg(i) {
var imgs = i.contentWindow.document.getElementsByTagName('img');
for(var i=0;i<
imgs.length
;i++)imgs[i]
.style.display
=
'none'
}
</script>
<iframe onload="hideImg(this)"