����� 4
�� 12: �������� ��� �������.
�� HTML �� ���� ������� ������: ()announceTime. �� ��� ����� �- announceTime ���� �����, ����� ����� �� ���� ���:
<a href="#" onClick="announceTime();">time!</a>
��� ���.
��� ���� ���� ���� ��� ������ ��' 2:
<a href="#" onClick="alert('Hello!');">Hello!</a>
�� ���� ���� ������ �� ����� ()alert ���� ����. ������� ��� ��� �����, ����� ������ ��� ������� ������ ��������. ����� �� ()alert �������� ��� ���� �������.
��� ����� �������� ����. �� ����� ���� �� ���� ��, ���� ����� ��������� ����� ���� ���� �- HTML. ��� ���:
<html>
<head>
<title>Function with No Parameters</title>
<script langauge="JavaScript">
<!-- hide me
function announceTime()
{
//get the date, the hour, minutes, and seconds
var the_date = new Date();
var the_hour = the_date.getHours();
var the_minute = the_date.getMinutes();
var the_second = the_date.getSeconds();
//put together the string and alert with it
var the_time = the_hour + ":" + the_minute + ":" + the_second;
alert("The time is now: " + the_time);
}
// show me -->
</script>
</head>
<body>
...
</body>
</html>
���, ����� ���� ��� ���� �� ��������. ��� �����, �� ��������� ���� ������ ���:
function functionName(parameter list)
{
statements ...
}
���� ����� �� ��������� �� ��� ���� �������. ������ ������� ����� ����� ��� �� �� ����. ��� ������� ������ ����� ������ �� ����� �������. ����� ���, ���� ����� �� ���� �� ���� �� ��� �������� �������. �� ���� �� ���� ������ ��� ������ ���� �����. ��� ����� ����� ����� ����� ��������� ��� �� ��� ����� ���� �� ���� ����� ���� �� �������� ������.
���� �� ��������, ����� ����� �� �������. �������� ���� ��� ��� �������, ���� ��� ���� �� ����� �������� ������ ����.
���� �������� �� ��� ��������. ��� �� �� ������ ���� ���� ���� �������� �����. ��� ����� �- timer �� �������� �����, �� ���� ����� ���� ��� ����.
����� �������:
var the_date=new Date();
����� ������� ����� (date) ���. ��� ���� ���� ����� ������� ���� ��� ����, ���� ���� ���� ����, �� ���� ����� ������� date ��� �� ��� ���� �� ����. ���� ��� ���� ������� date ���, ��������� ������ �� ���� ������ ����� ������. �� ��� ������ ���� ���������, ��� ���� ������ ������ �� ��������.
var the_hour = the_date.getHours();
var the_minute = the_date.getMinutes();
var the_second = the_date.getSeconds();
������� ���� ������ �� ������� �������� ���������. ��� ��� ���� �� ����, ��� ��� ���� ���� ��� ������� �� �������� date? ��� ��� ��� ��� ���� ��� ��� ����� ������� date? ���� ��� ����� ������ ���� �� ����� ������� �� JavaScript. ��� ���� ������ ��� ����� ��������� ������ �- JavaScript, ��� ��� ������ ���� ����� �� ����.
��� ��������� �� �� ������. ���� �� ����� ������ �������, ������ ���� �������, �� ����� �� ����� ()alert ����� ���� �� ������� ����� �������. ��� ��, ���� ���� ������ ������ ��������� ���� ���������. ����� ���� ��� ���� ������� ���.
�����, ������� ����� �� ����� �� �- timer, ���� ��� �� ����� ���� �����. �� ��� ��� ��� ���� ���� ���:"The time is now: 12:14:4". ��� �����?
�����, ������� ()getSeconed ������ ����. �� ���� ��� 12:14:4 �� ()getSeconeds ����� �� ���� 4. ���� ����� ������� �� �������� �"� the_minute + ":" + the_seconed, ���� 14:4, ����� �� ������. ���� ��� ��� ���� ���, �����: ����� ������� ���� ����� �� ����� �� ������ �� �� ������ �����. �������� ����� ����� ��� ����� �� �������� ������� �������, �����, ����� ������ ���� ���������, �� ��������� ����� ����� ��� ��� ����.
��� ���: �������, ������ ������.
���� ������ ���
��� ��� «--
|