注:火狐和ie获取display的方法不同,用前先判断,要不不兼容
var
currentstyle
=
function(e){
return
e.currentstyle
||
document.defaultview.getcomputedstyle(e,
null)
}
if(currentstyle(document.getelementbyid(id))['display']=='none'){
document.getelementbyid(divname).style.display
=
"block"
}else{
document.getelementbyid(divname).style.display
=
"none"
}
首先要取得top值和left值,先要把这个div的定位设为relative
或者
absolute
比如:
<div
id="tiao"
style="margin-top:
3margin-left:
-5width:
470height:
25position:relative"
></div>
top值:
document.getelementbyid('tiao').offsettop+document.body.scrolltop
left值:document.getelementbyid('tiao').offsetleft