就是默認顯示當前日期,點加號就顯示20161213 點減號就顯示20161215 ,這個要怎麼實現,謝謝各位大神。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="showDate">
<button class="sub" onclick="sub()">-</button>
<button class="add" onclick="add()">+</button>
<script>
var nowDate = new Date();
var myDate = nowDate.toLocaleDateString().replace(/\//g,'');
/*頁面加載結束顯示當前日期*/
window.onload=function(){
dateShow();
}
function add(){
myDate++;
// console.log(myDate);
dateShow();
}
function sub(){
myDate--;
// console.log(myDate);
dateShow();
}
/*讓日期顯示在input框中*/
function dateShow(){
document.getElementById('showDate').value=myDate;
}
</script>
</body>
</html>