我正在尝试将图像放置在由 javascript 函数生成的 div 标记中。问题是图像的位置不是距左侧 75 像素和距顶部 40 像素,而是停留在 0,0。这是代码。
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<HTML lang="en">
<HEAD>
<META http-equiv="Content-Type" content="text/html">
</HEAD>
<SCRIPT language = "JavaScript">
var my_div = null;
var newDiv = null;
function creatediv(id, width, height, left, top, opacity)
{
var newdiv = document.createElement('div');
newdiv.setAttribute('id', id);
newdiv.style.width = width + "px";
newdiv.style.height = height + "px";
newdiv.style.position = "absolute";
newdiv.style.left = left + "px";
newdiv.style.top = top + "px";
newdiv.style.opacity = opacity;
document.body.appendChild(newdiv);
my_div = document.getElementById(id);
document.body.insertBefore(newdiv, my_div);
}
</SCRIPT>
<BODY onload=" creatediv('logo', 792, 1000, 75, 40, 1)">
<div id = "logo" style=" z-index:1; font-size:200%; ">
<img src="some.gif" width="10%" height="10%">
</div>
</BODY>
</html>