你好每一個身體我需要時刻JS幫我叫開始輸入場和另一個叫停止之間的差異用2 JS時刻
start = moment().format('LT'); // works when i click on the play button
stop = moment().format('LT'); // works when i focus on the counter input beside the play button --> for test
我想改變開始輸入字段手動,所以我想一個驗證函數,它接受輸入值,並檢查輸入是否有效,如表格LT
例如:當我刪除輸入的值如下圖所示爲6:39 PM
,輸入例如6:02:00 PM or 1:00 PM or
添加一個字符串5:dfds2 PM
i想要控制檯記錄任何錯誤消息and return the previous value to the input again
也當我刪除當前值並添加一個數字,如'1例如'withou牛逼am or pm
所以它決定如果數字是之前或之後比停止輸入值和類型在這樣1:00 AM or 1:00PM
我用這個功能來驗證開始輸入字段輸入字段,但它給了我錯誤的答案
function validate(inputVal) {
let temp =this.startTime;
let x = temp;
if(moment(inputVal, "hh:mm").isValid()) {
x= moment(inputVal, "HH:mm").format('hh:mm A');
console.log("inputVal is: " + inputVal + " and x is: " + x);
this.startTime = x
} else {
this.startTime = "temp";
console.log("no");
}
}
這裏圖片 欲瞭解更多信息您可以訪問toggl website我的想法是從那裏取得的 任何幫助?! thanx提前
您的支票,如果'val'是有效的在這一行上:'moment(val,「hh:mm」)。isValid()'。你的意思是檢查你的'inputVal'? – enjoylife
@enjoylife當然這裏'val == inputVal'我更新了我的問題thx。 –