簡體   English   中英

如何從js獲取變量的值到index.html

[英]How to get variable's value from js to index.html

下面是我的 javascript 文件,其中包含這樣的

//custom.js
var setting = {
lastDate: '06/01/2016 09:18:00',   //Date format: month/day/year hours:minutes:seconds
timeZone: GMT +8,                    //GMT +10 or -5
style:{
    colorStart:'#3CEAEE',          //Background color start. Any #hex color, only 6 characters
    colorEnd:'#0d4266',            //Background color end. Any #hex color, only 6 characters
    bgStyle:'circularMiddleCenter' //Background style
}
};

所以在我的 index.html 中。 我如何從 js 文件中獲取 lastDate 值並進行比較?

我的 index.html 有一個始終處於禁用模式的按鈕,當到達 lastDate 時,使用當前日期 - lastDate 的概念。 然后按鈕將被啟用並執行操作。

<button>Let's Go</button>

有什么建議嗎?

您應該使用new Date()來獲取當前時間來完成您的目的

 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script> <script> //custom.js var setting = { lastDate: '5/30/2016 09:18:00', //Date format: month/day/year hours:minutes:seconds timeZone: "GMT +8", //GMT +10 or -5 style: { colorStart: '#3CEAEE', //Background color start. Any #hex color, only 6 characters colorEnd: '#0d4266', //Background color end. Any #hex color, only 6 characters bgStyle: 'circularMiddleCenter' //Background style } }; $(document).ready(function() { console.log((new Date().getTime() / 1000)); if ((new Date(setting.lastDate).getTime() / 1000) <= (new Date().getTime() / 1000)) { alert("reach"); } }); </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM