我想添加一個日期(也顯示給用戶)到我正在工作的Web應用程序中的用戶的每個列表輸入。如何將當前輸入日期添加到動態列表?
這是我的HTML代碼
<div id="todo">
<header>
<h1>To-Do List</h1>
<input id="new-todo" type="text" placeholder="Things you need to do...">
</header>
<section id='main'>
<ul id='todo-list'></ul>
</section>
</div>
和JavaScript是這裏
$(document).ready(function() {
function runBind() {
$('.destroy').on('click', function(e) {
$currentListItem = $(this).closest('li');
$currentListItem.remove();
});
$('.toggle').on('click', function(e) {
var $currentListItemLabel = $(this).closest('li').find('label');
if ($currentListItemLabel.attr('data') == 'done') {
$currentListItemLabel.attr('data', '');
$currentListItemLabel.css('text-decoration', 'none');
}
else {
$currentListItemLabel.attr('data', 'done');
$currentListItemLabel.css('text-decoration', 'line-through');
}
});
}
$todoList = $('#todo-list');
$('#new-todo').keypress(function(e) {
if (e.which === EnterKey) {
$('.destroy').off('click');
$('.toggle').off('click');
var todos = $todoList.html();
todos += ""+
"<li>" +
"<div class='view'>" +
"<input class='toggle' type='checkbox'>" +
"<label data=''>" + " " + $('#new-todo').val() + "</label>" +
"<a class='destroy'></a>" +
"</div>" +
"</li>";
$(this).val('');
$todoList.html(todos);
runBind();
$('#main').show();
}});
});
我應該在代碼添加到實現這一目標? 謝謝。
使用'日期()'來得到當前的日期和時間。 – Barmar