Drugpunker,
<!DOCTYPE HTML>
<html>
<head>
<title>Untitled</title>
<meta charset="utf-8">
<style type="text/css">
.time, input {
background: rgba(102, 255, 51, 1);
width: 80px;
height: 30px;
display: block;
text-align: center;
}
.div {
border: 1px #666 solid;
margin:2px;
}
</style>
<script>
function countdownTime(elem) {
var bet_time = new Date;
bet_time = bet_time.getTime() + 20000;
window.clearTimeout(elem.timer)
function calculate(elem) {
var now_time = new Date;
now_time = now_time.getTime();
var seconds = Math.ceil((bet_time - now_time) / 1000 * 1);
if (seconds > 0) {
residue = seconds < 10 ? "0" + seconds : seconds;
elem.innerHTML = "00:00:" + residue;
elem.timer = setTimeout(function () {
calculate(elem);
}, 1000);
} else {
elem.innerHTML = "Поехали";
}
}
calculate(elem);
}
function clickTimerButton(elem) {
return countdownTime(elem);
}
function clickTimerButton(elem) {
return countdownTime(elem);
}
/*window.onload = function () {
var span = document.querySelectorAll('.time');
for (var i = 0; i < span.length; i++) {
var el = span[i];
var button = document.createElement('input');
button.onclick = (function (span) {
return function () {
clickTimerButton(span)
}
})(el);
button.type = 'button';
button.value = 'Жмак!'
el.parentNode.insertBefore(button, el.nextSibling);
button.click()
}
}*/
</script>
</head>
<body>
<div class='div'>
<div><span class='time'></span></div>
<div>Кто нажал на кнопку</div>
<div><button>Жмак!</button></div>
</div>
<div class='div'>
<div><span class='time'></span></div>
<div>Кто нажал на кнопку</div>
<div><button>Жмак!</button></div>
</div>
<div class='div'>
<div><span class='time'></span></div>
<div>Кто нажал на кнопку</div>
<div><button>Жмак!</button></div>
</div>
</body>
</html>
|