here的简单方法:
document.write("<h1>result 1</h1>");
document.write("<h1>result 2</h1>");
如果您想在页面上的 DOM 中获取结果,那么如果您使用的是 jquery,请执行以下操作:
$(document.body).text(‘Result 1’);
如果你有多行结果:
$('<p>').text('result 1').appendTo($(document.body));
$('<p>').text('result 2').appendTo($(document.body));
这可能是这样的方法:
write(element: JQuery, text: string[]) {
text.forEach(v => {
$('<p>').text(v).appendTo(element);
});
}
你可以像这样使用它:this.write($('body'), ['result 1', 'result 2']);
如果不使用jquery,则编写如下方法:
write(element: HTMLElement, text: string[]) {
text.forEach(v => {
document.body.innerHTML += v + '<br>';
});
}
然后这样称呼它:this.write(document.body, ['result 1', 'result 2']);
如果您只想在控制台中查看结果,可以写console.log(’result 1’, ’result 2’)。您可以通过按 F12 在类似 Google Chrome Developer 的控制台中查看结果。