<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
截止时间:<input type="text" value="June 8 2018 11:45:00"/>
距离时间:<input type="text" />
<input type="button" value="按钮" />
<script>
var oInput = document.getElementsByTagName("input")
var now = null
var iNew = null
var timer = null
oInput[2].onclick = function(){
clearInterval(timer)
iNew = new Date(oInput[0].value)
timer = setInterval(function(){
now = new Date()
var t = Math.floor((iNew-now)/1000)
if(t>=0){
var d = Math.floor(t/86400)//天
var h = Math.floor(t%86400/3600)//时
var m = Math.floor(t%86400%3600/60)//分
var s = Math.floor(t%60)//秒
var str = d+"天"+h+"时"+m+"分"+s+"秒"
oInput[1].value = str
}else{
clearInterval(timer)
}
},1000)
}
</script>
</body>
</html>