MySQL ( до версии 5.6.5 ) не позволяет использовать функции для значений по умолчанию DateTime. TIMESTAMP не подходит из-за его нечетного поведения и не рекомендуется использовать в качестве входных данных. (См. Тип данных MySQL по умолчанию .)
Тем не менее, вы можете выполнить этот , создав триггер .
У меня есть таблицу с полем DateCreated типа DateTime. Я создал триггер в этой таблице «Before Insert» и «SET NEW.DateCreated=NOW()
», и он отлично работает.
Надеюсь, это поможет кому-то.
Поскольку, когда вы нажимаете кнопку, она исчезает, а таймер занял свою позицию, меняя положение кнопки на нижнюю часть timeRemaining
div и удаляя onclick="myFunction()"
, вы уже нажали id
$(document).ready(function() {
$("#startBtn").on("click", function() {
$(this).hide();
});
});
//set and display timer on button click
var timer = null;
var time = 0;
$("#startBtn").click(function() {
time = 120;
showTimer();
timer = setInterval(showTimer, 1000);
});
function showTimer() {
if(time < 0) {
clearInterval(timer);
return;
}
function pad(value) {
return(value < 10?'0':"") + value;
}
$("#timer").text(Math.floor(time/60)+':' + pad(time%60));
time--;
}
body {
background-image: url(https://www.joblo.com/assets/images/oldsite/newsimages1/avengers-infinity-war-main.jpg);
background-repeat: no-repeat;
background-size: 100%, 90%;
}
h1 {
text-align:center;
font-size: 100px;
color:white;
}
#startBtn {
width: 250px;
height:250px;
margin-left:450px;
margin-right:250px;
margin-top: 180px;
}
.timeRemaining {
color:white;
margin-left:350px;
font-size: 50px;
}
#timer {
color: white;
}
<!DOCTYPE html>
<html lang="en-us">
<head>
<title>Trivia Game</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-12">
<h1>Trivia Game</h1>
</div>
<div class="row">
<div class="col-lg-12">
<div class="timeRemaining">
<p>Time Remaining:
<span id="timer"></span>
</div>
</div>
<input type="image" id="startBtn" src="https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png" value="click me" />
</div>
<script src="assets/javascript/app.js"></script>
</div>
</body>
</html>