<script>
function numeri_validator(t) {
var patt = /(\d*)\.{1}(\d{0,2})/;
var donepatt = /^(\d*)\.{1}(\d{2})$/;
var str = t.value;
var result;
if (!str.match(donepatt)) {
result = str.match(patt);
if (result != null) {
t.value = t.value.replace(/[^\d]/gi, '');
str = result[1] + '.' + result[2];
t.value = str;
} else {
if (t.value.match(/[^\d]/gi))
t.value = t.value.replace(/[^\d]/gi, '');
}
}
//get the date
var val1 = document.getElementById("cost" + 1).value;
var val2 = document.getElementById("cost" + 2).value;
//Get date
var date = document.getElementById("Label1").innerText;
//format time
var timeIn = val1.replace('.', ':');
var timeOut = val2.replace('.', ':');
//Concat time with date
var timeinDate = date + " " + timeIn;
var timeoutDate = date + " " + timeOut;
//calculate time difference
var nDifference = Math.abs(new Date(timeoutDate) - new Date(timeinDate));
var one_hours = 1000 * 60 * 60;
var hours = (Math.floor(nDifference/one_hours));
var diff = nDifference % one_hours;
var one_min = 1000 * 60;
var diffmin = Math.round(diff/one_min);
document.getElementById("datelabel").innerText = hours + "." + diffmin;
document.getElementById("total").value = hours + "." + diffmin;
此功能calculatting兩個時間之間的區別是工作正常工作狀態,但只有在其他瀏覽器workong鉻是JavaScript的onkeyup事件僅適用於Chrome時間calculater
document.getElementById("total").value=NaN:NaN
請幫我
謝謝
什麼你的約會看起來像? Javascript可以解析的唯一格式是'YYYY-MM-DD'。 – Barmar
檢查我發佈的答案並進行更改。看看它是否有幫助。如果不是,請張貼您的HTML,以便我們可以進一步幫助您:) – MarsOne
日期格式爲'2013-10-18' – aas