用html写了一个框架分为上下两块,我想在上面块中为下面的块创建一个div
以下是我的源码
[code]
<!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" οnclick="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>
[/code]
这样做的错误在那里,请大家指点一二。谢谢!
以下是我的源码
[code]
<!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" οnclick="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>
[/code]
这样做的错误在那里,请大家指点一二。谢谢!