當前位置:編程學習大全網 - 編程軟體 - js編程編壹個程序,求當前時間距離元旦的剩余時間,在input文本框中顯示出來。

js編程編壹個程序,求當前時間距離元旦的剩余時間,在input文本框中顯示出來。

<!DOCTYPE?html>

<html>

<head>

<title>cc-vue.js</title>

<style?type="text/css">

</style>

<script>

//?生成2019年元旦日期函數

function?_yd()?{

var?yd?=?new?Date();

//?2019?-?01-01

//?Year

yd.setYear(yd.getFullYear()?+?1);

//?Month

yd.setMonth(0);

//?Day

yd.setDate(1);

//?Time

yd.setHours(0,0,0,0);

return?yd;

}

/**

?*?計算當前時間距元旦時間間隔

?*/

function?yd_cal()?{

var?ipt?=?document.getElementById('ipt');

var?now?=?new?Date();

var?ts?=?_yd().getTime()?-?now.getTime();

var?_d?=?ts?/?(24?*?60?*?60?*?1000);

//?console.log('天:'?+?parseInt(_d));

var?_h?=?(_d?-?parseInt(_d))?*?24;

//?console.log('小時:'?+?parseInt(_h));

var?_m?=?(_h?-?parseInt(_h))?*?60;

//?console.log("分鐘:"?+?parseInt(_m));;

var?_s?=?(_m?-?parseInt(_m))?*?60;

//?console.log("秒:"?+?parseInt(_s));;

ipt.value?=?"?"?+?parseInt(_d)?+?"天?"?+?parseInt(_h)?+?":"?+?parseInt(_m)?+?":"?+?parseInt(_s)?+?""?

}

</script>

</head>

<body?style="margin:?20px;">

<div?style="width:?100%;?height:?40px;?background-color:?#fff">

<label?for="ipt"?style="font-size:?.8em">當前距元旦時間間隔:</label>

<input?type="text"?value=""?placeholder="元旦時間間隔"?disabled?id="ipt">

<input?type="button"?value="計算"?onclick="yd_cal()"?/>

</div>

</body>

</html>

  • 上一篇:無錫龍林數控機械有限公司怎麽樣?
  • 下一篇:java裏面開頭前兩行代碼是什麽意思,求解答。本人編程小白在線求教。
  • copyright 2024編程學習大全網