我创建一个计时器,当有人使用webrtc记录音频时显示..我已经使用此功能。我想添加的是停止功能,因此每当用户点击停止时,计时器也会设置为超时。下面是示例代码..
// record start time
var startTime;
function display() {
// later record end time
var endTime = new Date();
// time difference in ms
var timeDiff = endTime - startTime;
// strip the miliseconds
timeDiff /= 1000;
// get seconds
var seconds = Math.round(timeDiff % 60);
// remove seconds from the date
timeDiff = Math.floor(timeDiff / 60);
// get minutes
var minutes = Math.round(timeDiff % 60);
// remove minutes from the date
timeDiff = Math.floor(timeDiff / 60);
// get hours
var hours = Math.round(timeDiff % 24);
// remove hours from the date
timeDiff = Math.floor(timeDiff / 24);
// the rest of timeDiff is number of days
var days = timeDiff;
$(".time").text(days + " days, " + hours + ":" + minutes + ":" + seconds);
setTimeout(display, 1000);
}
$("input#button").click(function () {
startTime = new Date();
setTimeout(display, 1000);
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div>
<input type="button" id="button" value="Start" />
</div>
<div class="time"></div>
&#13;
任何帮助将不胜感激。谢谢..