0

我试图通过java脚本获取开始时间和结束时间,但我不知道如何获得提交按钮它必须在提交按钮一侧运行多少时间来运行报告...

var begin_date = new Date();
//begin_time = begin.date.getTime();
begin_time = begin_date.getMilliseconds();
begin_date2 = begin_date;


var end_date = new Date();
//end_time = end_date.getTime();
end_time = end_date.getMilliseconds();
total_time = end_time - begin_time;


'Begin Time (ms): ' + begin_time;

'End time (ms): ' + end_time + "\n"+' Total time (ms): ' + total_time;

同样明智的是,我必须使用 javascript ...如何实现这一点?

4

2 回答 2

1

这是对您的目的没有帮助的代码

$(document).ready(function () {
var datetime = new Date();
var starttime = datetime.getTime();
$('#abc').click(function () {
    var datetime1 = new Date();
    var endtime = datetime1.getTime();

    alert(starttime);
    alert(endtime);
    var time_diff = starttime - endtime;
    alert(time_diff);
});

});


<input type=button value=button id='abc'>

我为此演示创建了一个演示小提琴

于 2013-09-17T05:49:43.553 回答
1

该脚本给出了从开始到结束经过的时间(直到按下提交按钮) - 时间以毫秒为单位。

脚本:

var begin_date;
var btime1,btime2,btime3,btime;
var etime1,etime2,etime3,etime;
var end_date;
function f1(){
begin_date = new Date();
btime1=begin_date.getHours();
btime2=begin_date.getMinutes();
btime3=begin_date.getSeconds();
}
function f2(){
end_date = new Date();
etime1=end_date.getHours();
etime2=end_date.getMinutes();
etime3=end_date.getSeconds();
total_time = end_date-begin_date;
}
$(document).ready(function(){
$("#b1").click(function(){
  f2();  
  $("#start").val(btime1+":"+btime2+":"+btime3);
  $("#end").val(etime1+":"+etime2+":"+etime3);
});
});

HTML:

<body onload="f1()">
<button id="b1">button</button><br/><br/>
START: <input type="text" id="start">
END: <input type="text" id="end" >
</body>
于 2013-09-17T05:21:52.280 回答