<script>
function startTimer(duration, display) {
var timer = duration,
minutes, seconds;
interval = setInterval(function() {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.text(minutes + ":" + seconds);
if (--timer < 0) {
alert("Time has ended");
$("#registration-form").submit()
clearInterval(interval);
}
}, 1000);
return new Date();
}
jQuery(function($) {
s = 10;
var Minutes = 60 * s,
display = $('#time');
var startDate = startTimer(Minutes, display);
$('button').click(function() {
var now = new Date();
var seconds = (now.getTime() - startDate.getTime()) / 1000;
$('#runtimes').append('<p>' + seconds + '</p>');
})
});
</script>
<div class="col-md-4">
<div class="test">Time Left <span id="time"></span>min</div>
</div>
<form name="frmRegistration" id="registration-form" method="post" action="index1.php">
<div id="runtimes" name="runtime"></div>
<button>Get run time</button>
</form>
https://jsfiddle.net/aruncool/vj84mc40/
在链接中显示单击按钮时已运行时间的值,我需要通过POST传递div ID值,并将其传递到另一页中,然后将该值插入db,但未通过传递值,这有助于我如何获取div ID值
最佳答案
您可以在表单中添加隐藏的输入,并在需要时更新其值。
的HTML
<input type="hidden" id="valueoftime" name="valueoftime">
jQuery查询
$('button').click(
var now = new Date();
var seconds = (now.getTime() - startDate.getTime()) / 1000;
$('#runtimes').append('<p>' + seconds + '</p>');
//Update input val
$("#valueoftime").val(seconds);
})