admin管理员组文章数量:1330597
I've only had a very quick preliminary search but is it possible to automatically change a specific element with javascript or jquery depending on the time?.. or by the local time of the puter who is viewing the webpage.
For instance say I have a <h2>Good Morning</h2>
display before 12pm, and then automatically it would change to to <h2>Good Afternoon</h2>
once it gets past this time.
I honestly, have not looked very deep into at all, but just wondering if this possible, and if so, is there a particular plugin that would aide me with this/what is the best way to do it?
I've only had a very quick preliminary search but is it possible to automatically change a specific element with javascript or jquery depending on the time?.. or by the local time of the puter who is viewing the webpage.
For instance say I have a <h2>Good Morning</h2>
display before 12pm, and then automatically it would change to to <h2>Good Afternoon</h2>
once it gets past this time.
I honestly, have not looked very deep into at all, but just wondering if this possible, and if so, is there a particular plugin that would aide me with this/what is the best way to do it?
Share Improve this question asked Nov 12, 2014 at 5:37 DanDan 131 silver badge3 bronze badges 2- 1 .getHours() and .text() – Regent Commented Nov 12, 2014 at 5:40
-
1
Yes it is possible and you don't need any plugins. You just need to check the docs on the
Date
object in javascript. – Vivek Pradhan Commented Nov 12, 2014 at 5:40
3 Answers
Reset to default 7Don't need jQuery.
document.getElementById('greeting').innerHTML = new Date().getHours() >= 12 ? 'Good Afternoon' : 'Good Morning';
Javascript's Date
object is you best bet to get the time.
http://www.w3schools./jsref/jsref_obj_date.asp
Once you know the time, it's easy to change the text in the header.
The text changes, might be done using cron job , if it is possible , you can do it just add or activate the css for the same element.
本文标签: javascriptChanging text depending on current timeStack Overflow
版权声明:本文标题:javascript - Changing text depending on current time? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742271153a2444328.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论