当我单击 div 框时,我似乎无法触发代码,它只是继续运行 onload。
<div id='tank' onclick="timer" style="position:relative; left:100px; top:240px;border- radius:360px;
background-color:green; height:100px; width:100px;"></div>
<script type="text/javascript">
(function () {
// don't leak variables into the global scope - think "variable = carbon dioxide"
var elem = document.getElementById('tank'), pos = 100,
timer = setInterval(function() {
pos++;
elem.style.left = pos+"px";
if( pos == 290) clearInterval(timer);
},12);
})();