xhtml的div的top和left值不能通过javascript传过来。。
xhtml 浮动窗口求debug。。本来应该div在左边 随着滚动条移动,但现在left和top属性完全不管用。。主要就是通过javascript来随时改变div的top和left值,alert发现确实把值传过去了,但是在就界面却不能呈现。如果我把整个文档改成html格式就没问题,但是xhtml这两个属性就没用,求解答
代码如下:
<div id="divstaytopleft" style="position:absolute" >
<layer id="divstaytopleft">
<!--EDIT BELOW CODE TO YOUR OWN MENU-->
<blockquote class="plan">
<center><h3>Plan of Study</h3>
<h3 id = "for"></h3></center>
<h3>Foundations area (<span id = "fc">0</span>/2)</h3>
<div id ="F"></div>
<h3>Cognitive area (<span id = "cc">0</span>/2)</h3>
<div id ="C"></div>
<h3>Systems area (<span id = "sc">0</span>/6)</h3>
<div id ="S"></div>
<h3>Tele and LIS area (<span id = "oc">0</span>/0)</h3>
<div id ="O"></div>
</blockquote>
<!--END OF EDIT-->
</layer>
</div>
<script type="text/javascript">
/*
Floating Menu script- Roy Whittle (http://www.javascript-fx.com/)
Script featured on/available at http://www.dynamicdrive.com/
This notice must stay intact for use
*/
//Enter "frombottom" or "fromtop"
var verticalpos="fromtop"
function JSFX_FloatTopDiv()
{
var startX = 900,
startY = 100;
var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function ml(id)
{
var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
if(d.layers)el.style=el;
el.sP=function(x,y){this.style.left=x;this.style.top=y;};
el.x = startX;
var a=document.getElementById("divstaytopleft");
a.setAttribute("left", ""+el.x+"px");
a.left=el.x;
var b=document.getElementById("divstaytopleft");
alert("b.left"+b.left);
if (verticalpos=="fromtop")
el.y = startY;
else{
el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
el.y -= startY;
}
return el;
}
window.stayTopLeft=function()
{
if (verticalpos=="fromtop"){
var pY = ns ? pageYOffset : document.body.scrollTop;
ftlObj.y += (pY + startY - ftlObj.y)/8;
var a=document.getElementById("divstaytopleft");
;
}
else{
var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
ftlObj.y += (pY - startY - ftlObj.y)/8;
var a=document.getElementById("divstaytopleft");
a.top=ftlObj.y;
}
ftlObj.sP(ftlObj.x, ftlObj.y);
setTimeout("stayTopLeft()", 10);
}
ftlObj = ml("divstaytopleft");
stayTopLeft();
}
JSFX_FloatTopDiv();
</script>
------解决方案--------------------
加xhtml声明后设置top,left这种有位置的和大小的需要加上单位px,要不不起作用,并且document.body要修改为