为什么循环执行函数不能单独放在外面呢?
<!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>
</head>
<body>
<div style="width:400px;margin:0 auto">
<img src="http://img1.sycdn.imooc.com//53577ee900016c2102080260.jpg" id="myImage" /><br />
<input type="button" id="max" value="放大" />
<input type="button" id="min" value="缩小" />
</div>
<script>
window.onload = function(){
var maxbtn=document.getElementById("max");
maxbtn.onclick=function(){
maxfun();
};
function maxfun(){
var img=document.getElementById("myImage");
var endwidth=img.style.width*1.3;
var maxwidth=img.style.width*1.5;
if(img.style.width==maxwidth){
clearInterval(timer)
}else{
if(img.style.width==endwidth){
clearInterval(timer)
}else{
img.style.width=img.style.width*1.05;
img.style.height=img.style.height*1.05;
}
}
}
var timer=setInterval(maxfun,1000);
}
</script>
</body>
</html>