����� 5
�� 7: CheckBoxes.
���� ����� ������ ����� �� �� ��� ��� ����� �� ������� �����. ��� ������ ����� ��� ������ �� ���� �- checkboxes, ������ ���� ������� �����. ���� ���� ������ �-checkbox. �-checkbox ���� ����� ��� ������� ������: ������� ������ (check).
�� �� �� ���� �����: the_form ��- checkbox ����: the_checkbox, ���� ����� �� �-checkbox ��� ���� �"� ���� ���:
var is_checked = window.document.the_form.the_checkbox.checked;
if (is_checked == true) {
alert("Yup, it's checked!");
} else {
alert("Nope, it's not checked.");
}
��� ���� ���� �� ������ �����, ������ ������ ���� ������� true. true ���� ��� ����� �- javaScript, ��� ��� ���� ���� ���� �������� ���� ��� ������ ���� ������ ���. �� �-checkbox ���� ����, ��� ������ ������ ���� false (�� ��� �����).
��� ���� ���� ����� �� ������ ����� �- checkboxes, �� �� ���� ����� �� ����. ���� ����� ������ ����� �� ������ ������.
<form name="form_1">
<input type="checkbox" name="check_1">Checkbox 1<br>
</form>
<a href="#" onClick="window.document.form_1.check_1.checked=true; return false;">Click to check Checkbox 1</a> <br>
<a href="#" onClick="window.document.form_1.check_1.checked=false; return false;">Click to uncheck Checkbox 1</a> <br>
<a href="#" onClick="alert(window.document.form_1.check_1.checked); return false;">Click to see the value of Checkbox 1</a>
��� �� ��� ���� ����� false ���� �- href, �"� ����� ���� ����� ���� ��� ���� �� �������.
�- checkbox �� ����� ������� ������: �- onClick. ���� ����� ���� �� �-checkbox ������ �� �- onClick �����. ��� �����:
����� �� ����� ������ ���� ������ ��������: �����, ����� ������ �� �- onClick �� ����� ������� �� �- checkbox.
<form name="form_2">
<input type="checkbox" name ="check_1" onClick="switchLight();">The Light Switch
</form>
���� ����� ���� �� �- checkbox ����� ������� �� onClick ����� ����� ����� �������� ()switchLight. ��� �������� ()switchLigt:
function switchLight()
{
var the_box = window.document.form_2.check_1;
var the_switch = "";
if (the_box.checked == false) {
alert("Hey! Turn that back on!");
document.bgColor='black';
} else {
alert("Thanks!");
document.bgColor='white';
}
}
���� ������� ������ ����� ����� �������:
var the_box = window.document.form_2.check_1;
���� �� ���� �� ������� �- checkbox ������. ���� ��� ������ ���� ������. ����� ���, ��� �� ������ ������ ��������� �������� ���������. ����� ���� ��� ���� ������� ���� �������� �����.
��� ��� ����� ���� ���� ���� �� checkbox, ������, ����� ����� �� ������ �����.
���� ������ ���
��� ��� «--
|