我用本章節的內容寫了一段代碼,結果瀏覽器老是崩潰fierfox和chrome都出現這種問題
求教下大神這是什么原因???還有時間下方的效果也出不來
<!DOCTYPE?html>
<html>
<head>
<meta?charset="utf-8">
<meta?http-equiv="X-UA-Compatible"?content="IE=edge,chrome=1">
<title>Examples</title>
<meta?name="description"?content="">
<meta?name="keywords"?content="">
<link?href=""?rel="stylesheet">
</head>
?<script?type='text/javascript'>
??function?clock(){
???var?mytime=new?Date();
???var?mydate=mytime.getFullYear()+'年'+mytime.getMonth()+'月'+mytime.getDate()+'日';
???var?m=mytime.getMinutes();
???var?h=mytime.getHours();
???var?s=mytime.getSeconds();
???var?t;
???m=startTime(m)
???s=startTime(s)
???document.getElementById("tm").innerHTML=mydate+h+':'+m+':'+s+'</br>';
???t=setInterval('clock()',500)
??}
??function?startTime(i){
????if(i<10){
????????i="0"+i
????}
????return?i
??}
?var?user_hf=window.location.href;?
?var?user_na=navigator.userAgent;
?var?user_sc_hg=screen.availHeight;
?var?user_sc_wd=screen.availWidth;
?document.getElementById('us').innerHTML=user_hf+'</br>'+user_na+'</br>'+user_sc_hg+';'+user_sc_wd;
</script>?
<body?onload='clock()'>
<b?id='tm'></b>
<span?id='us'></span>
</body>
</html>
2016-04-12
你要把
t=setInterval('clock()',500)寫在clock函數外面
寫在函數里面就成無限遞歸了。函數每執行一次,都會有個setInterval事件,資源大大的占據
2016-11-04
把setInterval改成setTimeout也可以執行時間
2016-04-17
你在body里面運行的clock這個函數里面的內容。
2016-04-12
(首先我是個學渣 )
然后 應該是循環出BUG了吧 ?
我好像也遇到了類似問題?瀏覽器就無響應了 打開任務管理器發現“服務主機:本地服務(網絡受限)”使磁盤飆到了70%多 ?
這個有關系嗎 ?求解