<html><head><title></title>
<script language="javascript">
var initTop=document.body.offsetHeight;
function init()
{
document.write("<div id=layer1 style='position:absolute; width:196px; top:initTop;height:52px;z-index:1;background-color:red;'></div>")
}
</script>
<style type="text/css"></style>
</head><body onload=init()>
</body></html>
我是这么添加,可是结果不对,请问有什么方法可以在脚本中添加标签吗?
<script language="javascript">
var initTop=document.body.offsetHeight;
function init()
{
document.write("<div id=layer1 style='position:absolute; width:196px; top:initTop;height:52px;z-index:1;background-color:red;'></div>")
}
</script>
<style type="text/css"></style>
</head><body onload=init()>
</body></html>
我是这么添加,可是结果不对,请问有什么方法可以在脚本中添加标签吗?
function init()
{
var initTop=document.body.offsetHeight;
document.write(" <div id=layer1 style='position:absolute; width:196px; top:"+initTop+";height:52px;z-index:1;background-color:red;'> 123123</div>")
}
</script>
</body>
<script language="javascript">
function init()
{
var initTop=document.body.offsetHeight;
document.write(" <div id=layer1 style='position:absolute; width:196px; top:"+initTop+";height:52px;z-index:1;background-color:red;'> 123123</div>")
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD> <BODY>
<SCRIPT LANGUAGE="JavaScript">
<!--
var div=document.createElement("DIV");
div.id="div1";
div.style.background="yellow";
div.style.width="120px";
div.style.height="200px";
div.innerText="哈哈哈哈哈";
document.body.appendChild(div);
//-->
</SCRIPT>
</BODY>
</HTML>
<html>
<head>
<title> </title>
<script language="javascript">
function init()
{
var initTop=document.body.offsetHeight;alert(initTop)
document.write("<div id=layer1 style='position:absolute;width:196px;top:"+initTop+"px;height:52px;z-index:1;background-color:red;'></div>")
}
</script>
<style type="text/css"> </style>
</head> <body onload=init()>
</body>
http://download.csdn.net/source/308916DHTML参考手册.rar
http://download.csdn.net/source/308913样式表中文手册.chm
http://download.csdn.net/source/304124
initTop作为变量来用的,不能直接跟在top:后面