今天的车把日期

时间:2018-03-01 14:35:06

标签: node.js express handlebars.js express-handlebars

有人可以帮助我在车把文件中获取今天的日期吗? 输出应该是"今天是星期四" 。  `

<script>
  var today = new Date();
  var day = today.getDay();
  var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
  var x = document.getElementById("MyP").innerHTML;
  x = x + daylist[day];
  document.getElementById("MyP").innerHTML = x;
</script>

 <h2 class="page-header">Dashboard</h2>
<p>Welcome to {{user.username}}</p>
<p id="MyP"></p>

`

我一直在尝试这种方式,但某种程度上它不起作用

1 个答案:

答案 0 :(得分:1)

试试这个。确保<script>标记位于HTML之后,否则当脚本执行时,HTML尚未就绪。

<h2 class="page-header">Dashboard</h2>
<p>Welcome to {{ user.username }}</p>
<p id="MyP">Today is </p>

<script>
    var today = new Date();
    var day = today.getDay();
    var daylist = ["Sunday","Monday","Tuesday","Wednesday ","Thursday","Friday","Saturday"];
    document.getElementById("MyP").innerHTML += daylist[day];
</script>