Javascript - 如果id等于'test',则更改div的文本

时间:2014-11-28 14:58:39

标签: javascript date

感谢所有人的贬低... var date = new Date(year, month, day, hours, minutes, seconds, milliseconds); doesn't work!

新问题:如何将div内的文本更改为true或false? 代码:

function getDate() {
var today = new Date();
var year = today.getFullYear();
var month = today.getMonth()+1;
var day = today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
var milliseconds = today.getMilliseconds();
var date = new Date(year, month, day, hours, minutes, seconds, milliseconds);
var date2 = new Date(2014,11,1,22,00,00);
if (date === date2) {
document.getElementById("test").innerHTML = "true";
}
else
{
document.getElementById("false").innerHTML = "false";
}
}

由于某种原因,这不起作用:(,是的,div已经测试为id -Bram

1 个答案:

答案 0 :(得分:2)

请先阅读一些文档:http://www.w3schools.com/js/js_dates.asp

var date = new Date(year, month, day, hours, minutes, seconds, milliseconds);