如何将CSS样式应用到iframe内容?

Vin*_*rum 5 html css iframe

我想在iframe中为内容应用CSS样式,请查看此链接http://jsfiddle.net/pPqGe/

jQuery的:

$(document).ready(function() {
    $('iframe').contents().find('h1').css('color','red');
});
Run Code Online (Sandbox Code Playgroud)

HTML:

<iframe src="mysite" width="100%" height="100%" id="myframe"></iframe>
Run Code Online (Sandbox Code Playgroud)

对于iframe来源,我使用了一个实时网站.

小智 7

有用.问题是没有H1,只有H2.看看这个链接http://jsfiddle.net/pPqGe/1545/.

HTML:

<iframe src='jsfiddle.net'></iframe>
Run Code Online (Sandbox Code Playgroud)

JavaScript的:

$(document).ready(function() {
    $('iframe').contents().find('h2').css('color','red');
    $('iframe').contents().find('#header').css('opacity','.2');
});
Run Code Online (Sandbox Code Playgroud)