繁体   English   中英

写入HTML页面

[英]Writing onto HTML page

因此,对于简短的上下文,我的程序读取一个文件并将其显示在html页面上。 下面的代码使用一个正则表达式来读取该文件并提取错误。 不用每次都使用console.log进行调试,有什么办法可以将结果写到HTML页面上吗?

当我使用时:

document.getElementById("").innerHTML 

它只会打印出最后的摘要,而不是打印出所有摘要。

我尝试使用控制器和ng-repeat(AngularJS)来执行此操作,但是以某种方式我做得不好。

任何想法-不必在AngularJS中使用???

while ((match = reDiaBtoa.exec(reader.result)) != null) {
    if (match.index === reDiaBtoa.lastIndex) {
        reDiaBtoa.lastIndex++;
    }

    // View your result using the match-variable.
    // eg match[0] etc.
    // extracts the status code: ERROR

    if (match[2] === "ERROR" || match[2] === "FATAL" || match[2] === "SEVERE") {
        console.log("Time: " + match[1]);
        console.log("Thread Name: " + match[3]);
        console.log("Source name & line number: " + match[4]);
        console.log("Log Message: " + match[5] + '\n');
        console.log("-----------------------------------------------------------------");
    }
} //end of the while loop ((match = reDiaBtoa.exec.....))

如果您使用

document.getElementById("someId").innerHTML =

它将覆盖现有的html。

相反,使用

document.getElementById("someId").innerHTML +=

在while循环之前创建一个字符串变量,然后在循环中附加到它:

var outputToDisplay = "";
//While loop
outputToDisplay += "Time: " + match[1];
//etc

//End While
document.getElementById(theId).innherHTML = outputToDisplay;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM