错误消息".innerHTML不是函数"; [英] Error message ".innerHTML is not a function"
本文介绍了错误消息".innerHTML不是函数";的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在表格标题中自动填写日期,但是我得到的只是
I'm trying to fill the date automatically in a table header, but all I get is
.innerHTML不是函数"
".innerHTML is not a function"
我到处都看过,尝试将我的代码放在页面的顶部和底部,但是没有任何效果.请帮忙!
I've looked everywhere, and tried put my code at the top and bottom of the page, but nothing works. Help, please!
window.onload = function() {
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
document.getElementById("dated").innerHTML(month + "/" + day + "/" + year);
};
推荐答案
好吧,正如错误所示,innerHTML
不是函数.
Well, as the error says, innerHTML
is not a function.
尽管,您可以为属性分配一个值:
document.getElementById("dated").innerHTML = month + "/" + day + "/" + year;
有关更多信息,请参阅 MDN文档 .
For more infos, have a look at the MDN docs.
这篇关于错误消息".innerHTML不是函数";的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文