js를 사용하여 현재 시간 표시 example_jquery

WBOY
풀어 주다: 2016-05-16 16:57:42
원래의
1068명이 탐색했습니다.

페이지가 전경에 표시됩니다

코드 복사 코드는 다음과 같습니다.


js 스크립트

코드 복사 코드는 다음과 같습니다.

$(document) .ready( function () {
//첫 번째 유형
showTime();
//두 번째 유형
var clock = new Clock();
clock.display($( "#시계"));
});

//현재 시스템 시간을 표시하는 첫 번째 방법
function showTime() {
var myArray = new Array(7);
var TD = new Date();
myArray[ 0] = "일요일";
myArray[1] = "월요일";
myArray[2] = "화요일";
myArray[3] = "수요일";
myArray[4 ] = "목요일";
myArray[5] = "금요일";
myArray[6] = "토요일";
weekday = TD.getDay();
var h = TD.getHours( );
var m = TD.getMinutes();
var s = TD.getSeconds();
var hstr = h;
var mstr = m;
var istr = s ;
if (h < 10) { hstr = "0" h };
if (m < 10) { mstr = "0" m };
if (s < 10) { istr = "0" s };
$("#clock").innerHTML('현재 시간:' new Date().toLocaleDateString() " " myArray[weekday] " " hstr ":" mstr ":" istr );
setTimeout(showTime, 1000);
}

//현재 시스템 시간을 표시하는 두 번째 방법
function Clock() {
var date = new Date();
this.year=date.getFullYear();
this .month=date.getMonth() 1;
this.date=date.getDate();
this.day=newArray("일요일","월요일","화요일","수요일"," 목요일 ","금요일","토요일")[date.getDay()];
this.hour=date.getHours()<10?"0" date.getHours():date.getHours();
this. Minute=date.getMinutes()<10?"0" date.getMinutes():date.getMinutes();
this.second=date.getSeconds()<10?"0" 날짜 .getSeconds():date.getSeconds();

this.toString=function(){
return "현재 시간:" this.year "연도" this.month "월" this.date "일" this.hour ":" this.분 " : " this.second "" this.day;
};

this.toSimpleDate=function(){
returnthis.year "-" this.month "-" this.date;
};

this.toDetailDate=function(){
returnthis.year "-" this.month "-" this.date "" this.hour ":" this. Minute ":" this.second;
};

this.display=function(ele){
varclock=newClock();
ele.innerHTML=clock.toString();
window.setTimeout(function(){clock.display(ele) );},1000);
};
}

관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
최신 이슈
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!