文章詳情頁
javascript - setInterval和document.write在IE瀏覽器下的沖突
瀏覽:103日期:2023-03-22 08:20:56
問題描述
function reload(){ alert('ce');}window.onload=function(){ alert('a'); setInterval('reload()',1000); document.write('aaa');};
如上,同時有 setInterval 和 document.write在其他極速瀏覽器,chrome內核瀏覽器里沒有問題。但是在 IE11 瀏覽器里,setInterval 就會停止。怎么解決。謝謝。
問題解答
回答1:document.write會隱式調用document.open。這樣會重構document,移除所有event事件和task。
可以用document.body.innerText代替document.write
function reload(){ alert('ce');}window.onload=function(){ alert('a'); setInterval('reload()',1000); document.body.innerText = 'aaa';};
標簽:
JavaScript
上一條:javascript - 為什么 body 高度比 canvas 高度多出4個像素?下一條:javascript - 求助在 requireJS 中,$(window).load() 里面的代碼 為什么不會執行?
相關文章:
排行榜
