加上remove后失效,注釋掉remove又可以了,為什么,大神們幫幫忙
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<div id="div">
</div>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById("div");
oDiv.onmouseover=function(){
startMove();
}
oDiv.onmouseout=function(){
reMove();
}
}
var timer=null;
function startMove(){
clearInterval(timer);
? ? ? ? ? ?var oDiv=document.getElementById("div");
? ? ? ? ? ?
? ? ? ? ? ?timer=setInterval(function(){
? ? ? ? ? ? if (oDiv.offsetLeft==500) {
? ? ? ? ? ? clearInterval(timer);
? ? ? ? ? ? }?
? ? ? ? ? ? else {
? ? ? ? ? ? oDiv.style.left=oDiv.offsetLeft+1+"px";
? ? ? ? ? ? }
?
? ? ? ? ? ? },10)
? ? ? ? function reMove(){
clearInterval(timer);
? ? ? ? ? ?var oDiv=document.getElementById("div");
? ? ? ? ? ?
? ? ? ? ? ?timer=setInterval(function(){
? ? ? ? ? ? if (oDiv.offsetLeft==0) {
? ? ? ? ? ? clearInterval(timer);
? ? ? ? ? ? }?
? ? ? ? ? ? else {
? ? ? ? ? ? oDiv.style.left=oDiv.offsetLeft-1+"px";
? ? ? ? ? ? }
?
? ? ? ? ? ? },10)
? ? ? ? ? ??
}
</script>
</body>
</html>
2016-05-29
在瀏覽器里用F12調(diào)試之后發(fā)現(xiàn)你在?startMove()這個函數(shù)處少寫了“ } ”。38行后面。