Realization of Real time Time Acquisition by jQuery Code

  • 2021-07-16 01:09:52
  • OfStack

In the last article introduced to you jQuery dynamic access to the system time implementation code, you can refer to the following.

No more nonsense, just post the code for everyone. The specific code is as follows:


$(document).ready(function(){
function time(){
var date=new Date();
var h=date.getHours();
var m=date.getMinutes();
var s=date.getSeconds();
$('div').eq(0).html(h);
$('div').eq(1).html(m);
$('div').eq(2).html(s);
for(var i=0;i<$('div').length;i++){
if($('div').eq(i).text().length==1){
$('div').eq(i).html(function(index,html){
return 0+html;
});
}
}
}
time();
setInterval(time,1000);
}) ; 

HTML Part


<div></div>
<div></div>
<div></div>

The above is the site to introduce the jQuery code to achieve real-time access to time function, I hope to help you, if you have any questions welcome to leave me a message, this site will reply to you in time!


Related articles: