日期:2014-05-16 浏览次数:20477 次
<script type="text/javascript"> function dao(timeDao) { var sh=null; divD.innerText=timeDao; if(timeDao==0) { clearInterval(sh1); return; sh=1; } timeDao--; if(sh==null){ sh1=setInterval("dao("+timeDao+")",100); } } </script> <div id="divD" onclick="dao(10,null)">执行10次</div>
<div id="divD" onclick="dao.start(10)">执行10次</div>
------解决方案--------------------
楼主,其实没有那么的复杂,给你个简单的:
<!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" xml:lang="cn"> <head> <meta http-equiv="Content-Type" content="text/html;charset=gb2312" /> <title></title> </head> <body> <script type="text/javascript"> function dao(timeDao){ document.getElementById("divD").innerHTML = timeDao; timeDao--; if(timeDao >= 0 ){ setTimeout(function(){ dao(timeDao); }, 1000); } } </script> <div id="divD" onclick="dao(10)">执行10次</div> </body> </html>
------解决方案--------------------
<div id="divD" onclick="dao(10,this)">执行10次</div> <script type="text/javascript"> function dao(timeDao, elem) { var timer = setInterval(function(){ if(timeDao >= 0){ elem.innerHTML = timeDao; timeDao--; }else{ clearInterval(timer); } }, 100); } </script>