Javascript 点击按钮停止JS秒倒计时

Javascript 点击按钮停止JS秒倒计时,javascript,php,Javascript,Php,我有一个计时器: var seconds = 0; var el = document.getElementById('seconds-counter'); function incrementSeconds() { seconds += 1; el.innerText = "You have been here for " + seconds + " seconds."; } var cancel = setInterval(incrementSeconds, 1000);

我有一个计时器:

var seconds = 0;
var el = document.getElementById('seconds-counter');

function incrementSeconds() {
    seconds += 1;
    el.innerText = "You have been here for " + seconds + " seconds.";
}

var cancel = setInterval(incrementSeconds, 1000);
如果可能的话,我如何让计时器停止并将经过的秒数转换为PHP变量$eassed_time?
我需要这个,因为当表单提交到数据库时,PHP代码必须计算这个时间以及其他变量。如果有某种解决方法,我很欢迎。

为什么在PHP中需要它?JavaScript就足够了。您可以使用clearInterval()停止间隔,然后进行AJAX POST调用,将值传输到服务器端PHP脚本。不能直接从JavaScript设置PHP变量。