如何在 html 正文中显示 javascript var

2022-01-17 00:00:00 numbers javascript html var

我正在寻找一种在 html 页面正文中调用 javascript 编号的方法.这不必冗长而奢侈,只需简单地工作,我只想要这样的东西:

I am looking for a way to call a javascript number in the body of an html page. This does not have to be long and extravagant just simply work, I just want something like:

<html>
<head>
<script type="text/javscript">
var number = 123;
</script>
</head>

<body>
<h1>"the value for number is: " + number</h1>
</body>
</html>

推荐答案

试试这个...

<html>

<head>
  <script>
    function myFunction() {
      var number = "123";
      document.getElementById("myText").innerHTML = number;
    }
  </script>
</head>

<body onload="myFunction()">

  <h1>"The value for number is: " <span id="myText"></span></h1>

</body>

</html>

相关文章