<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值
答案 0 :(得分:4)
您可以在表单中添加隐藏的输入,并在需要时更新其值。
<强> 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);
})