[英]How to get variable's value from js to index.html
Below is my javascript file which contain like this下面是我的 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
}
};
So in my index.html.所以在我的 index.html 中。 how do i get the lastDate value from the js file and do comparison?
我如何从 js 文件中获取 lastDate 值并进行比较?
My index.html have a button which always in disable mode, and when the lastDate reached, concept using current Date - lastDate.我的 index.html 有一个始终处于禁用模式的按钮,当到达 lastDate 时,使用当前日期 - lastDate 的概念。 then the button will be enabled back and do actions.
然后按钮将被启用并执行操作。
<button>Let's Go</button>
Any suggestion?有什么建议吗?
You should use new Date()
to get the current time to do your purpose您应该使用
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.