我正在尝试从java脚本中打印我的html中的内容。我做了这个,但它不起作用:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>I am trying to print <script>go();</script></p>
<script>
function go() {
document.write("Hello World!");
}
</script>
</body>
</html>
答案 0 :(得分:3)
您所发布的示例中尚未定义您的功能,因此调用go有效无效,更改脚本标记的顺序
<!DOCTYPE html>
<html>
<head>
<script>
function go() {
document.write("Hello World!");
}
</script>
</head>
<body>
<p>I am trying to print <script>go();</script></p>
</body>
</html>