车把中的今天日期
Todays Date in Handlebars
谁能帮我在 handlebar 文件中获取今天的日期?
输出应该类似于 "Today is Thursday" 。
`
<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>
`
我一直在尝试这种方式,但不知何故它不起作用
试试这个。确保 <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>
谁能帮我在 handlebar 文件中获取今天的日期? 输出应该类似于 "Today is Thursday" 。 `
<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>
`
我一直在尝试这种方式,但不知何故它不起作用
试试这个。确保 <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>