이 기사 예제는 JS가 웹 페이지에서 간단한 표시 시간을 구현하는 방법을 설명합니다. 참조를 위해 공유하십시오. 세부 사항은 다음과 같습니다.
이것은 웹 클럭 JS 코드, 순수한 JavaScript 구현, 시간, 분 및 초를 표시합니다. 웹 타임 디스플레이와 웹 시계가 많이 있으며, 정말 간단합니다. 훌륭한 예술가와의 친구들은 이것을 기반으로 더 아름답게하고 향상시킬 수 있습니다.
코드를 다음과 같이 복사하십시오.
<html xmlns = "http://www.w3.org/1999/xhtml">
<헤드>
<meta http-equiv = "content-type"content = "text /html; charset = utf-8" />
<title> 간단한 웹 시계 </title>
<스타일>
바디, div {마진 : 0; 패딩 : 0;}
바디 {색상 : #ffff; font : 16px/1.5/5fae/8f6f/96c5/9ed1;}
#Clock {너비 : 300px; 텍스트-정렬 : 중심; 배경 :#1a1a1a; 마진 : 10px 자동; 패딩 : 20px 0;}
span {color :#000; 너비 : 80px; 선-높이 : 2; 배경 : #fbfbfb; 테두리 : 2px 솔리드#b4b4b4; 마진 : 0 10px; 패딩 : 0 10px;}
</스타일>
<cript>
Window.onload = function ()
{
var oclock = document.getElementById ( "clock");
var aspan = oclock.getElementsByTagName ( "span");
SetInterval (GetTimes, 1000);
getTimes ();
함수 getTimes ()
{
var odate = 새로운 날짜 ();
var adate = [odate.gethours (), odate.getminutes (), odate.getSeconds ()];
for (var i in adate) aspan [i] .innerhtml = 형식 (Adate [i])
}
함수 형식 (a)
{
return a.tostring (). 교체 (/^(/d) $/, "0 $ 1")
}
}
</스크립트>
</head>
<body>
<div id = "clock">
<span> </span> 포인트 <span> </span> 분 <span> </span> 초
</div>
</body>
</html>
이 기사가 모든 사람의 JavaScript 프로그래밍에 도움이되기를 바랍니다.