如何在 html 正文中显示 javascript var [英] how to display a javascript var in html body

查看:31
本文介绍了如何在 html 正文中显示 javascript 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>

这篇关于如何在 html 正文中显示 javascript var的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆