文章詳情頁
javascript - setInterval和document.write在IE瀏覽器下的沖突
瀏覽:142日期: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() 里面的代碼 為什么不會執行?
相關文章:
1. javascript - vscode alt+shift+f 格式化js代碼,通不過eslint的代碼風格檢查怎么辦。。。2. javascript - [js]為什么畫布里不出現圖片呢?在線等3. python - 如何判斷爬蟲已經成功登陸?4. html - vue項目中用到了elementUI問題5. html5 - 有可以一次性把所有 css外部樣式轉為html標簽內style=" "的方法嗎?6. javascript - 如何將一個div始終固定在某個位置;無論屏幕和分辨率怎么變化;div位置始終不變7. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?8. javascript - 有什么比較好的網頁版shell前端組件?9. javascript - 這不是對象字面量函數嗎?為什么要new初始化?10. javascript - 求解答:實例對象調用constructor,此時constructor內的this的指向?
排行榜
