關(guān)于格式問(wèn)題
格式里面是setInterval(“clock()”,1000)或者setInterval(clock,1000)我寫(xiě)了一個(gè)點(diǎn)擊按鈕移動(dòng)的寫(xiě)錯(cuò)了寫(xiě)成了setInterval(clock(),1000)發(fā)現(xiàn)還是可以只不過(guò)是要點(diǎn)擊一次執(zhí)行一次不會(huì)一直自己執(zhí)行,當(dāng)然改正后會(huì)一直執(zhí)行。
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
#div1{
width:200px;
height:200px;
border:2px solid red;
position:absolute;
left:0px;
top:0px;
? ? ? ?z-index:-1;
}
</style>
<script type="text/javascript">
function startqwe(){
var qwe=document.getElementById('div1');
function moveqwe(){
//
qwe.style.left=qwe.offsetLeft+1+'px';
qwe.style.top=qwe.offsetTop+1+'px';
}
setInterval(moveqwe(),30);
}
</script>
</head>
<body>
<div id="div1"></div>
<input type="button" value="點(diǎn)擊開(kāi)始運(yùn)動(dòng)" onclick="startqwe()" />
</body>
</html>
2017-03-30
自己蠢了那樣其實(shí)是錯(cuò)誤寫(xiě)法導(dǎo)致定時(shí)器沒(méi)起作用只是執(zhí)行button罷了