javascript 无法读取未定义的属性“getTime”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24261772/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot read property 'getTime' of undefined
提问by saji
I am getting this error while trying to set up a counter which calculates the total time taken to fill a particular form .Have tried the following things,
我在尝试设置一个计数器时遇到此错误,该计数器计算填写特定表格所需的总时间。已尝试以下操作,
//script
var timeStart;
var timeStop;
$(document).load(function() {
timeStart = new Date();
});
$('#form_3').on('submit', function() {
timeStop = Math.round((timeStart.getTime() - new Date().getTime()) / 1000);
console.debug('time taken from load till submit: ' + timeStop);
});
//script
//脚本
now getting error uncaught TypeError:Cannot read property 'getTime' of undefined.
现在得到错误未捕获 TypeError:Cannot read property 'getTime' of undefined。
回答by Nishanthi Grashia
May be you can try (new Date()).getTime())
:
也许你可以尝试(new Date()).getTime())
:
timeStop = Math.round((timeStart.getTime() - (new Date()).getTime()) / 1000);