如何在iframe外控制iframe中的css
1个回答
2016-06-20
展开全部
请看下列代码(已经测试,可行!):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<iframe id="FF" src="B.htm"></iframe>
<input type="submit" value=" OK " onclick="OK()"/>
<script language="JavaScript">
function OK()
{
// 操作iframe中内容的CSS
var iframe = document.getElementByIdx('FF');
var body = iframe.contentWindow.document.body;
body.style.marginTop = 50;
body.style.padding = 0;
body.style.fontSize = 30;
body.style.textAlign = 'center';
body.style.backgroundColor = 'red';
body.style.color = 'blue';
}
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>
<body>
<iframe id="FF" src="B.htm"></iframe>
<input type="submit" value=" OK " onclick="OK()"/>
<script language="JavaScript">
function OK()
{
// 操作iframe中内容的CSS
var iframe = document.getElementByIdx('FF');
var body = iframe.contentWindow.document.body;
body.style.marginTop = 50;
body.style.padding = 0;
body.style.fontSize = 30;
body.style.textAlign = 'center';
body.style.backgroundColor = 'red';
body.style.color = 'blue';
}
</script>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询