日期:2014-05-16  浏览次数:20647 次

document.getElementById(divID).style.left IE可以而谷歌不行
 用了这句话,document.getElementById(divID).style.left 。IE可以而谷歌不行
------解决方案--------------------
如果是获取的话,你可以尝试如下,不过设置left,应该不存在兼容问题
<!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=utf-8" />
<title>无标题文档</title>
<style>
.box{width:500px;height:100px;background:#6FF;position:absolute;left:30px;}

</style>
<script>
window.onload=function()
{
var oBox=document.getElementById('box');
alert(getStyle(oBox,'left'));
}
function getStyle(obj,attr)
{
if(obj.currentStyle)
return parseFloat(obj.currentStyle[attr])
------解决方案--------------------
0;
return parseFloat(getComputedStyle(obj,0)[attr])
------解决方案--------------------
0;
}
</script>
</head>

<body>
<div class="box" id="box">
</div>
</body>
</html>

------解决方案--------------------
设置属性的话,要加单位
document.getElementById(divID).style.left = "100px";