����� 3
�� 5: ���� JavaScript.
���� ��� ���:
��� �� ����� ���� ���� (start clock) ������ �� �����. ���� �� ���� �� ���� ������ ��� ������ �� ���� ����� �� ��� ����. ��� ���� �� ����� ��� ���� �����. �������, ���� ����� ����� ������ ����� �"� ������� ������ �����. �������, ����� �� ���� �� ��� ���� �� Date object, ���� ������ ���� ���� ������ �� Cookies.
��� ����:
function writeTime() {
// get a date object
var today = new Date();
// ask the object for some information
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
// fixTime makes the minutes and seconds look right
// it just sticks a zero in front of numbers less than 10
minutes = fixTime(minutes);
seconds = fixTime(seconds);
// put together the time string and write it out
var the_time = hours + ":" + minutes + ":" + seconds;
window.document.the_form.the_text.value = the_time;
// run this function again in half a second
the_timeout= setTimeout('writeTime();',500);
}
function fixTime(the_time) {
if (the_time < 10)
{
the_time = "0" + the_time;
}
return the_time;
}
�� ���� ���� ��� ����, ���� ������ �����. ��� ����� �� ���� ���� ��� ����:
var today = new Date();
��� �- ()new Array ����� ������� ���� ������ ������ ����, ()new Date ����� ������� ��� ���� �����. ���� ��� �� �� ��������, ��� ���� ������ ���� ����� �� ����. ���� ��� ���� ������� ����� �� ��� ��� ��� ��������, ��� ���� �����, JavaScript ������ �� ����� �� ����� ������� �� ����� ������� ����� ���. ���, ���� ��� ������� �����, ����� "today", ��� ������ ����� ���� ���� �� ����.
var hours = today.getHours();
����� �� ���� ���� ������ �� ���� �������. ��� ��� ����, ��� �� ����� 2 p.m. ���� ����� �� ()getHours,�������� ����� "today" ����� "14". ��� �� ()getHours ��� ����� call ��� ��� ��� �������� ����� ������� ������ �� JavaScript. ��� ����� �� ���� ���� �������� JavaScript, ���� ���� ���� ���� ������ �- getHours ��� �"� ����� ���� ��� �� JavaScript ���� ������.
var minutes = today.getMinutes();
var seconds = today.getSeconds();
����� ��� �� ����� ��� ����� ������ �� ����� getHours.
���� ��� �� getMinutes ��� ��� ���� ��� 11:01, ������ getMinutes ����� �� ���� "1". �� ���� ��� �� �� ��� ���� ����� ���� ��� ���� �����, ������� ���, ��� ����� �� "1" ����� �- "01". �� �� �������� fixTime ������ ����. ���� ������� �� �����, ���� ��� �� ������ ������ ����. ���� ��� ��� ��� ����� �� ��� ����.
��� ������ ����� ������ �� ������� ���� ������� ���� �-form element.
����� ��� ��� ��� �� ������ ������ �����.
the_timeout = setTimeout('writeTime();', 500);
���� ����� ��� ����� �� ������. ��� ����� "���� ���� �����, ��� �������� ���". ���� �������� ����� ���, ��� ����� ��� �� ()today = new Date, ���� ���� ���� �����. ������ ���� ����� �� �����, ��� ����� ��� �� ��� ����� ���� ����� ����� ���� ����� ����.
���, ����� �� ���� ���� ���� ������. �� ��� ��� ��� ���� ���� ���� ���� ����� ���: ��� ������ ��� �� ������.
���� ������ ���
��� ��� «--
|