oDiv.style.left=100+"px"; //不报错 // oDiv.style.left=100px; 会报错?原代码如下
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#div{
position: absolute;
width: 100px;
height:100px;
background-color: red;
}
</style>
</head>
<body>
<div id="div">
</div>
</body>
<script>
var oDiv =document.getElementById("div");
div.onmousedown=function(){
oDiv.style.left=100+"px"; //不报错
// oDiv.style.left=100+"px"; 会报错
}
</script>
</html>