为什么Jquery在使用set minutes函数设置时间后显示当前系统时间? [英] Why Jquery displays current system time after setting time using set minutes function?

查看:73
本文介绍了为什么Jquery在使用set minutes函数设置时间后显示当前系统时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么Jquery在设置分钟功能设置时间后显示当前系统时间?



 <   html  >  
< head >
< script src = https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery .min.js > < / script >

< script >
var ser_hours,ser_min utes,ser_seconds;
var ser_date = new Date();
函数updateClock()
{
// var currentTime = new Date();
var currentHours = ser_date.getHours();
var currentMinutes = ser_date.getMinutes();
var currentSeconds = ser_date.getSeconds();

//使用前导零填充分钟和秒数,如果需要,
currentMinutes =(currentMinutes < 10 0 + currentMinutes;
< span class =code-attribute>
< span class =code-attribute> currentSeconds = currentSeconds < 10 0 + currentSeconds;



// 选择 AM PM as 适当

var timeOfDay = currentHours < 12 AM PM;



// 转换 小时 组件 to 12小时 格式 if

currentHours = currentHours > 12)? currentHours - 12:currentHours;

//将小时组件0转换为12
currentHours =(currentHours == 0)? 12:currentHours;

//为显示组成字符串
var currentTimeString = currentHours +:+ currentMinutes +:+ currentSeconds ++ timeOfDay;


$(#clock)。html(currentTimeString);

}
函数getClock_server()
{
var ser_date = new Date();
// ser_hours = d.hours; ser_minutes = d.minutes,ser_seconds = d.seconds
$ .get('http://127.0.0.1/readytoupload/time.php?time',function(d){ser_date.setMinutes(d.minutes) ; ser_date.setSeconds(d.seconds); ser_date.setHours(d.hours);});
}
$(document).ready(function()
{
getClock_server();
setInterval('updateClock()',1000);
});
< / script >
< head >
< body >
< div id = clock > < / div >

< / body >
< / HTML >







http:// 127.0.0.1/readytoupload/time.php?time返回以下json



{小时:06,分钟:19,秒 :22}

解决方案

(#clock)。html(currentTimeString);

}
函数getClock_server()
{
var ser_date = new Date();
// ser_hours = d.hours; ser_minutes = d.minutes,ser_seconds = d.seconds


.get('http://127.0.0.1/readytoupload/time.php?time',function(d){ser_date。 setMinutes(d.minutes); ser_date.setSeconds(d.seconds); ser_date.setHours(d.hours);});
}


(document).ready(function()
{
getClock_server();
setInterval('updateClock()', 1000);
});
< / script >
< head >
< body >
< div id = clock > < / div >

< / body >
< / HTML >







http:// 127.0.0.1/readytoupload/time.php?time返回以下json



{小时:06,分钟:19,秒 : 22}


Why Jquery displays current system time after setting time using set minutes function?

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

<script>
var ser_hours, ser_minutes, ser_seconds;
var ser_date = new Date();
function updateClock ( )
    {
    //var currentTime = new Date ( );
    var currentHours = ser_date.getHours ( );
    var currentMinutes = ser_date.getMinutes ( );
    var currentSeconds = ser_date.getSeconds ( );

    // Pad the minutes and seconds with leading zeros, if required
    currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;

    currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;



    // Choose either "AM" or "PM" as appropriate

    var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";



    // Convert the hours component to 12-hour format if needed

    currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;

    // Convert an hours component of "0" to "12"
    currentHours = ( currentHours == 0 ) ? 12 : currentHours;

    // Compose the string for display
    var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;


    $("#clock").html(currentTimeString);

 }
function getClock_server ()
{
    var ser_date = new Date();
    //ser_hours = d.hours; ser_minutes = d.minutes, ser_seconds = d.seconds
    $.get('http://127.0.0.1/readytoupload/time.php?time', function (d) { ser_date.setMinutes(d.minutes); ser_date.setSeconds(d.seconds); ser_date.setHours(d.hours);});
}
$(document).ready(function()
{
    getClock_server();
   setInterval('updateClock()', 1000);
});
</script>
<head>
<body>
<div id="clock"></div>

</body>
</html>




http://127.0.0.1/readytoupload/time.php?time Returns following json

{"hours":"06","minutes":"19","seconds":"22"}

解决方案

("#clock").html(currentTimeString); } function getClock_server () { var ser_date = new Date(); //ser_hours = d.hours; ser_minutes = d.minutes, ser_seconds = d.seconds


.get('http://127.0.0.1/readytoupload/time.php?time', function (d) { ser_date.setMinutes(d.minutes); ser_date.setSeconds(d.seconds); ser_date.setHours(d.hours);}); }


(document).ready(function() { getClock_server(); setInterval('updateClock()', 1000); }); </script> <head> <body> <div id="clock"></div> </body> </html>




http://127.0.0.1/readytoupload/time.php?time Returns following json

{"hours":"06","minutes":"19","seconds":"22"}


这篇关于为什么Jquery在使用set minutes函数设置时间后显示当前系统时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆