eg:下课倒计时
<body><p id="app"></p><script>function handleTime(value){if(value<10){return "0" +value;}return ""+value;}function showTime(){var endTime = "2020-12-01 16:50:00";var app = document.getElementById("app")endTime = new Date(endTime).getTime();var nowTime = new Date().getTime();var gapTime = endTime - nowTime;var seconds = Math.floor(gapTime/1000);var hours = handleTime(Math.floor(seconds/3600));seconds %=3600;var minutes = handleTime(Math.floor(seconds/60));seconds =handleTime(seconds%60);var sum = hours +":" + minutes +":" +seconds;app.innerHTML=sum;setTimeout(function(){showTime();},1000)}showTime();</script></body>
eg:动态时钟
:
:
<a name="j2CWK"></a>## eg:字符串模板(可以在字符串中使用变量)```javascript<script>var str = 10;var b = "hello";console.log(str+b); //10hellovar sum = `${str}hello`;console.log(sum); //10hello</script>
eg:回调函数(将函数作为参数,传递给另一个函数)
场景:一般在异步调用中使用
作用:1. 将函数内部的值返回到外面
2. 取代了return语句
<script>
var show = function(res){
console.log(res); //10
}
function go(callback){
var a =10;
callback(a);
}
go(show);
</script>
And:
<script>
function go(callback){
var a =10;
callback(a);
}
go(function(res){
console.log(res) //10
})
</script>

