【发布时间】:2020-09-27 09:29:05
【问题描述】:
<!DOCTYPE html>
<html lang="en">
<head>
<title>JavaScript Example</title>
<script>
function displayString() {
return "<h1>Main Heading</h1>"
}
displayString();
document.write("Execute during page load from the head<br>");
</script>
</head>
<body>
<script>
document.write("Execute during page load from the body<br>");
</script>
</body>
</html>
所以这是我的问题。无论我将 displayString() 放在哪里,h1 似乎都不会出现在浏览器上。谁能帮我看看我错在哪里?我是 JavaScript 新手。哦,我想做的是调用这个函数。
【问题讨论】:
-
哇,这个问题有两个人赞成..!!
-
是的,就好像有人要求投票一样,也许是他们认识的人或回答的人?虽然那会违反规则,所以,不,不能那样吗?!
-
你“正确地”调用了函数——你只是没有对函数的返回值做任何事情,例如在对 document.write 的调用中使用它以将其作为内容添加到文档中。
标签: javascript html function call