Javascript document.write中的行消失
我的代码首先生成以下两行: 1,2,3,4,5 1,2,3,4 1,2,3,4,5 1,2,3,4 然后它产生这些线,这两条线消失了: 1,2,3 1,2 1 1,2,3 1,2 1. 为什么会这样Javascript document.write中的行消失,javascript,arrays,Javascript,Arrays,我的代码首先生成以下两行: 1,2,3,4,5 1,2,3,4 1,2,3,4,5 1,2,3,4 然后它产生这些线,这两条线消失了: 1,2,3 1,2 1 1,2,3 1,2 1. 为什么会这样 var arr=[1,2,3,4,5]; document.write(arr+"</br>"); function popit() { if(arr.length>0) { arr.pop(); if(arr.length<=0)
var arr=[1,2,3,4,5];
document.write(arr+"</br>");
function popit() {
if(arr.length>0) {
arr.pop();
if(arr.length<=0) {
clearTimeout(p);
document.write("end");
}
var p=setTimeout(popit,1000);
document.write(arr);
document.write("</br>");
}
}
window.onLoad=popit();
var-arr=[1,2,3,4,5];
文件。写入(arr+“”;
函数popit(){
如果(arr.length>0){
arr.pop();
如果(arr.length在页面加载完成后使用document.write()
,使用window.onLoad=popit()
,它将基本上清除正文的HTML并开始添加新内容。不要使用document.write()
。如果必须输出到屏幕,请添加到document.body.innerHTML
或者,您也可以只查看这里的console.log(arr)