gpt4 book ai didi

javascript - 在 HTML onload Javascript 中输入日期

转载 作者:行者123 更新时间:2023-11-28 19:57:43 24 4
gpt4 key购买 nike

我正在尝试输入页面加载时的当前日期。我能够将其存储到变量中,只是在将该变量输入到页面上时遇到问题。

HTML:

<span id='test'>x</span>

Javascript:

window.onload = function() {
var month = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth();
var currentMonth = month[mm];
var yyyy = today.getFullYear();
today = currentMonth + ' ' + dd + ', ' + yyyy;
document.getElementById('test').innertext() = today;
}

JSFIDDLE

最佳答案

更改此:

document.getElementById('test').innertext() = today;

为此:

document.getElementById('test').innerHTML = today;

关于javascript - 在 HTML onload Javascript 中输入日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22234600/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com