由於某種原因,真的很擔心這部分。比較給定時間和當前時間的多個倒數計時器?
我正在創建一個計時器,可以用來跟蹤出價。我希望能夠比較兩次,並在倒計時欄中顯示差異(以分鐘和秒爲單位)。它應該比較現在的出價開始時間和時間。
也許,當它達到出價開始時,它也可能會改變,直到出價結束爲止。最終,我想在接近時間後添加背景更改,也許可以通過提示窗口設置鬧鐘。
這裏是我到目前爲止的代碼:
HTML
<table>
<tr>
<td>Item Name</td>
<td><input id="itemNameField" placeholder="" type="text"></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td>Time of Notice</td>
<td><input id="noticeField" type="time"></td>
</tr>
</table>
<input id="addButton" onclick="insRow()" type="button" value="Add Timer">
<div id="errorMessage"></div>
<hr>
<div id="marketTimerTableDiv">
<table border="1" id="marketTimerTable">
<tr>
<td></td>
<td>Item Name</td>
<td>Time of Notice</td>
<td>Bid Start</td>
<td>Bid End</td>
<td>Countdown</td>
<td></td>
</tr>
<tr>
<td></td>
<td>
<div id="itembox"></div>Example Item
</td>
<td>
<div id="noticebox"></div>12:52
</td>
<td>
<div id="bidstartbox"></div>13:02
</td>
<td>
<div id="bidendbox"></div>13:07
</td>
<td>
<div id="countdownbox"></div>
</td>
<td><input id="delbutton" onclick="deleteRow(this)" type="button" value="X"></td>
</tr>
</table>
</div>
JAVASCRIPT
function deleteRow(row) {
var i = row.parentNode.parentNode.rowIndex;
if (i == 1) {
console.log = "hi";
} else {
document.getElementById('marketTimerTable').deleteRow(i);
}
}
function insRow() {
if (itemNameField.value == "" || noticeField.value == "") {
var div = document.getElementById('errorMessage');
div.innerHTML = "*Please fill in the fields*";
div.style.color = 'red';
document.body.appendChild(div);
} else {
var div = document.getElementById('errorMessage');
div.innerHTML = "";
var x = document.getElementById('marketTimerTable');
var new_row = x.rows[1].cloneNode(true);
var len = x.rows.length;
var inp1 = new_row.cells[1].getElementsByTagName('div')[0];
inp1.id += len;
inp1.innerHTML = itemNameField.value;
itemNameField.value = "";
var inp2 = new_row.cells[2].getElementsByTagName('div')[0];
inp2.id += len;
inp2.innerHTML = noticeField.value;
noticeField.stepUp(10);
var inp3 = new_row.cells[3].getElementsByTagName('div')[0];
inp3.id += len;
inp3.innerHTML = noticeField.value;
noticeField.stepUp(5);
var inp4 = new_row.cells[4].getElementsByTagName('div')[0];
inp4.id += len;
inp4.innerHTML = noticeField.value;
var inp5 = new_row.cells[5].getElementsByTagName('div')[0];
inp5.id += len;
inp5.innerHTML = "";
noticeField.value = "";
x.appendChild(new_row);
}
}
我提前道歉,因爲我的代碼可能是非常的混亂和格式錯誤。以下是JSFIDDLE!謝謝:)
我一直在使用這種嘗試,但它只是似乎很混亂和尷尬讓它做什麼,我想要它是因爲「noticeField.value.split」....我覺得將noticeField時間轉換成秒,然後找出差異會更好。儘管如此,我仍然努力尋找它 – Sarah
由於只有一個Date對象,我們可以使用它來以毫秒爲單位獲得差異,因此我們需要將小時和分鐘轉換爲毫秒。這需要我們更多的努力和計算,這就是爲什麼提出上述解決方案的原因。如果您找到解決此問題的其他方法,請告訴我。 –
我試過這個,但計算只是完全錯誤,我不能解決原因。如此混淆...... 'var noticeTimeMinutes =(noticeTime [0] * 60)+ noticeTime [1] + 5; var currentTimeMinutes =(currentDate.getHours()* 60)+ currentDate.getMinutes(); var diffTotalMinutes =(noticeTimeMinutes - currentTimeMinutes);' – Sarah