我有一个带有嵌入式iframe的页面,我需要设置iframe中显示的元素的样式。问题是我无法编辑iframe(我认为它是相同的来源,但不确定),所以我需要通过父框架中的代码来设置iframe内容的样式。我试图通过选择器执行此操作,但没有成功。
例如:
<html>
<body>
<iframe id="frame">
<div id="target">target</div>
</iframe>
</body>
</html>
CSS方法:
#frame #target{
background:red;
}
jQuery方法:
$("#frame #target").css({'background':'red'});
最佳答案
您可以使用函数: