���� ������ ��:
1: JavaScript �����
2: ����� ������
3: ������ ����� ������
4: ����� �����
5: ����� ����� ���
6: ����� �-JavaScript
7: �� ���� ����?
|
| | | | | | | | |
����� 5
�� 2: ����� ������.
���� ���� ���� ���, ��� ���� ������ ����. ����� ����, ����� ������ �������� ���� ���� ����� ���, ��� ��� ����� ������ ��� ������ �� ����� ����� ������.
��� ������� ������� �������� ����� ������ ����� ��� ������. ����, ���� ������ ������ ���� ���� ��� ��� ������� ����� �� �� ����. ��� ���� ��� �� ���� �� ��� ��������� �����:
function getName()
{
var first_name = prompt("what's your first name?","");
var last_name = prompt("what's your last name?","");
var the_name = first_name + " " + last_name;
}
function theGreeting()
{
var the_name = "";
the_name = getName();
if (the_name == "Dave Thau")
{
alert("Hello, oh greatest one!");
} else {
alert("Ahoy palloi!");
}
}
��� �� ����� ��� ���� �� ��� ���� �� �� ���� (�������� �- Netscape 3.x ���� ���� ����� ������ ������� ���� ���� ������; ����� ����� ������ ���� �� �������� �- JavaScript �����). �� ��� ����� ���� ������� �� ����� �������, ���� �� ����� "Ahoy palloi!". ��� ����, �� ����� �� ��� "Dave" ���� ���� �-prompt ������� �- "Thau" �����, ��� ���� ���� �� ������ "Hello, oh greatest one!" ����� ���, ����� ���� ����� "Ahoy palloi!" . ���� �� ���� �� ���� �� ���������. ������ ����� ��, ���� �� ������� �� �"� �������� ���� �- JavaScript. ��� ����, ��� �������� ��� ���� ���� ����� �����, ����� ������� �� �"� ����� ����� ����� ���� ������.
�� JavaScript ���� ����� �� ����� ���, ����� ���� �� "�� ����" �� �"� ������� ������� ���, ������ ���� ������ �� �������. ���� ���� ����� ����� ��� ��� �� ()alert, ��:
// theGreeting gets a name using getName, then presents one or two
// alert boxes depending on what the name is
//
function getName()
{
var first_name = prompt("what's your first name?","");
var last_name = prompt("what's your last name?","");
var the_name = first_name + " " + last_name;
alert("in getName, the_name is: " + the_name);
}
// theGreeting gets a name using getName, then presents one of two
// alert boxes depending on what the name is
//
function theGreeting()
{
var the_name = "";
the_name = getName();
alert("after getName, the_name = " + the_name);
if (the_name == "Dave Thau")
{
alert("hello, oh greatest one!");
} else {
alert("ahoy palloi!");
}
}
��� �� �� ������ �� ()alert ��� ������� �������. ��� ��� �� ����� ��
����� ������. �� ����� �� ����� "Dave" �- "Thau", ���� �� �- alert ������� ������: "in getName, the_name is: Dave Thau",
��� �- alert ������ ������: "after getName, the_name = undefined", �� ����� �� ����� ������� ����� ���� ���� �- ()getName. ������, the_name ���� ���� ���� ����� ���� ������ ���������, ��� theGreeting ���� �� ���� ������ the_name. ���� ��� ���� ������� ����� ��� ����, �� �� �� ����� ������ ����, ���� ������ ����� ����� ���, �� ����� �� ���� ����� ����. ���� ����, ������ ����� ��. ������� �- ()getName ����� �� ���, ��� ����� ���� ������ ����. ��� ������ ������ ";return the_name" ���� ���������.
���� ���� ���� ���� ����� ����� ���� ���. ���� ����, ��� ����� ����� �� ����� �- "OK" ���� ��� ����.
���� ���� ���� ������, �� ��� ����� �� ������ ����� ��� ��� ����� ����� �����. ������ ��� ��� ����� �� ������ ����� ������ ���, ����� ���� ���� ����. ������ ����� ��� ����� �� ������ ����� ������ ����� ����. ���� ����� �� ��� ����� ����� ��� ���� ������ ����� ����� ����� ����� ���
���� ���� ��� ���� ����� �� ������ ����� ������ ��� ������ ����� ����, ���� ����� ����� ����� �� ����� ����� ��� ����� ����� ����� ����� "debug". ���� ��� �- JavaScript:
// debug can be either none, alert, or textarea depending
// on the kind of debugging I want to do
//
var debug = "none";
// function getName gets a first and last name, concatenates
// them with a space in between, and returns the name
//
function getName()
{
var first_name = prompt("what's your first name?","");
var last_name = prompt("what's your last name?","");
var the_name = first_name + " " + last_name;
var error_message = "in getName, the_name is: " + the_name;
doError("in getName, the_name is: " + the_name);
}
// theGreeting gets a name using getName, then presents one of two
// alert boxes depending on what the name is
//
function theGreeting()
{
var the_name = "";
the_name = getName();
doError("after getName, the_name = " + the_name);
if (the_name == "Dave Thau")
{
alert("hello, oh greatest one!");
} else {
alert("ahoy palloi!");
}
}
// doError is the error handling routine
// depending on the type of debug message
// it presents either no debug message, an alert
// or puts the message in a textarea
//
function doError(the_message)
{
if (debug == "alert")
{
alert(the_message);
} else if (debug == "textarea") {
window.document.the_form.the_text.value += the_message + "<br>\n";
}
}
��� �� �� ������ �� ������ ����� "debug" ��� ���� ����� "none", "alert" �� "textarea". ��� �� ��� ���� ���� ������ �����, ��� ���� �� ������� �������� doError(). ������� �� ����� �� ����� �� ������: �� ����� ����; ����� ���� ����� �� �����; ���� ������ ����� ����. �������� "�����" �� ��� ���� ����� �� ����� ����� ������. ��� ���� ����� �� ����� ����� ������ �- "textarea", ���� �� �� ���� ������ ��� ��� ���� ������ ���� ���������. ���, ����� ���� ������ �� ���� ��� �����, ��� ���� ����� �� ����� ������ �-"none", ������ ������ �� ����� ���, �� ����� �� �� ����� ��������� ����� ������ �� �� ������ ����� ������.
������ ������, ������� ������ ����� ����� �� ����� �����, ��� "none" (��� �����), "brief" (��� �����) �- "extreme" (���� �����). "brief" ����� ���� ������ �� ����� ����� ����� ����, �-"extreme" ����� ���� ������ ����� �����, ���� �- "none", �����, �� ����� �� �����.
�� ���� �� ����� ����� ������ ��� ����� ���, ��� ���� ����� �� ���� ����� ������ �- "brief" ���� ��� ����, ��- "none" ���� ��� ������ ����� �� �- JavaScript. �� ���� ���� ������� ����� �����, ����� ���� ���� ���� ��� �����, ��� ���� ����� �� ���� ����� ������ �- "extreme" ������� ��� ��� �� ������ ����� ������ �� ����� ���� ����.
���, ����� �� ������ ����� �����. ��� ���� ����� ������� ������ ��� ������� �"� ������ JavaScript.
���� ������ ���
��� ��� «--
|
|