`
hamburg
  • 浏览: 114562 次
  • 来自: 不污染一方土地
社区版块
存档分类
最新评论

如何在一个框架中为另一个框架创建元素

阅读更多
用html写了一个框架分为上下两块,我想在上面块中为下面的块创建一个div
以下是我的源码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>框架</title>
</head>

<frameset rows="80,*">
   <frame src="a1.html" name="topFrame" scrolling="No"  id="topFrame" title="topFrame" />
   <frame src="a2.html" name="mainFrame" id="mainFrame" title="main" />
</frameset>
<noframes>
<body>
</body>
</noframes></html>

a1.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<script type="text/javascript">
function show() {
	var oSpan = document.createElement("div");
	oSpan.style.display = '';
	oSpan.style.top = 0;
	oSpan.style.left = 0;
	oSpan.id = "asdfasdf";
	oSpan.style.position = 'absolute';
	oSpan.style.width = '100px';
	oSpan.style.height = '100px';
	oSpan.innerText = '信息....';
	alert(window.top.mainFrame.document.body);
	document.body.appendChild(oSpan);
	top.mainFrame.document.body.appendChild(oSpan);
}
</script>
<body>
<input name="aaaa" type="button" value="aaaaa" onclick="show()" />
<span id="span_">asdfasdf</span>
</body>
</html>
a2.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>

<body>
<span id="span_">55555555555555555555555555555</span>
</body>
</html>

这样做的错误在那里,请大家指点一二。谢谢!
分享到:
评论
1 楼 roki 2007-07-18  
window.top.mainFrame这句不对, 没有拿到正确的节点,
建议用iebar或者ff的dom工具看一下节点的正确路径

相关推荐

Global site tag (gtag.js) - Google Analytics