我试图在显示新任务(obj)时将页面上的当前日期打印为时间戳,但无论何时制作时间戳,新时间戳都是相同的日期。任何帮助将不胜感激。
function getDate() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
var time = today.getTime();
if (dd < 10) {
dd = '0' + dd
}
if (mm < 10) {
mm = '0' + mm
}
today = mm + '/' + dd + '/' + yyyy + ' ' + time;
localStorage.setItem('newDate', today);
var newDate = localStorage.getItem('newDate');
return (newDate);
}
function show() {
var todos = get_todos();
var date = localStorage.getItem('newDate');
var html = '<table>';
for (var i = 0; i < todos.length; i++) {
html += '<br><tr><strong>' +
'<input type="image" src="Pictures/remove.png" class="remove" id="' + i +
'"></input>' + todos[i] + ' - ' + date + '</strong><input type="checkbox" name="cBox" id="isDone"><label for="cBox"</label></tr><br>';
};
html += '</table>';
document.getElementById('todos').innerHTML = html;
var buttons = document.getElementsByClassName('remove');
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener('click', remove);
};
}
document.getElementById('add').addEventListener('click', add);
show();