Πίσω στην αρχική μου σελίδα |
• Java Script
Calculator
Samples: Calculator
Πως δουλέυει? Ο υπολογιστής είναι ένας HTML
πίνακας που περιέχει button controls. Τα ίδια τα κουμπιά είναι
intrinsic <INPUT> style buttons, όχι Microsoft® ActiveX®
controls. Microsoft® JScript® code εφαρμόζεται στο OnClick
event γι' αυτά buttons. Το αποτέλεσμα είναι απλώς ένα intrinsic
<INPUT> style text box. Παρατήρούμε τις μεταβλητές (variable) δηλώνονται στην αρχή του <SCRIPT> tag, έξω από κάθε διαδικασία(procedure:)
<SCRIPT
LANGUAGE="JavaScript"> <!-- // Module-level
variables var FKeyPad = document.Keypad; var Accum = 0;
// Previous number (operand) awaiting operation var
FlagNewNum = false; // Flag to indicate a new number (operand)
is being entered var PendingOp = ""; // Pending operation
waiting for completion of second operand . . . δες τον κώδικα
για τα υπόλοιπα
These are module-level variables that
persist for as long as the page is loaded. By contrast,
variables declared within a procedure cease to exist as soon
as the procedure exits. Thus, module-level variables can be
used to store values that must persist between invocations of
a procedure. Module-level variables are also visible to all
procedures, and so are useful when multiple procedures need to
share values.
|
|
| |