1. A,N,R,I
(Off)
[ 29 Sep 2013, 21:32 ]
daprogramebis ena JavaScript
JavaScript-i daprogramebis ena gamoiyeneba HTML dokumen-
tebis Sesaqmnelad. enis mTavari aspeqti aris obieqtis cneba.
literalebi literalebi literalebi literalebi
martivi monacemebi razedac SeiZleba agebuli iqnas prog-
rama aris literalebi. mTeli tipis mudmivebi SeiZleba moce-
muli iqnas aTobiTi TeqvsmetobiTi, an rvaobiTi formiT.
mTeli tipis aTobiTi mudmivebi SeiZleba warmodgenili
iyos niSniT an niSnis gareSe magaliTad 15,125, -156 +3546.
TeqvsmetobiTi ricxvebi Seicaven cifrebs 0-9-mde da
asoebs a,b, c, d. e,f.
TeqvsmetobiTi ricxvebi iwereba ricxvis win simboloTi
0x, magaliTad 0x25, 0xa1, 0xff.
rvaobiTi ricxvebi Seicaven mxolod cifrebs 0-dan 7-is
CaTvliT daiwereba ase 03, 0543. 011.
aTwiladi ricxvebis Casawerad, rogorc yvela daprogra-
mebis enaSi mZimis nacvlad gamoiyeneba wertili. magaliTad,
123. 45, -56.789.
aTwiladi ricxvebis Casawerad gamoiyeneba eqsponencialu-
ri forma magaliTad, ricxvi 0,000000234 romelic SeiZleba ase
warmovadginoT 2.34x10-7 JavaScript daprogramebis enaze Caiwereba
2.34e-7.
aTobiTi da mTeli mudmivebis garda arsebobs logikuri
mudmivebi, romlebic iReben mxolod or mniSvnelobas WeSmari-
ti – true zogierT warmodgenaSi - 1, mcdari- false – 0.
striqonuli literali warmoadgens simboloebis Tanmim-
devrobas romelic moTavsebulia ‘ ‘ an “ “ simboloebSi.
magaliTad “ Sedegi” an ’Sedegi’. carieli striqonuli cvladi
aRiniSneba ‘ ‘ an “ ” simboloebiT.
cvladi cvladi cvladi cvladi
cvladebi gamoiyeneba monacemebis Sesanaxad. cvladebis
aRwera xdeba identifikatoris saSualebiT. identifikatori
aucileblad unda iwyebodes laTinuri alfavitis asoTi an
gaxazvis simboloTi , Semdeg SeiZleba Cawerili iyos cifri an
gaxazvis simbolo. magaliTad test1, _my-test, test-1. cvladis tipi
ganisazRvreba maTSi Senaxuli monacemebis tipiT, monacemebis
tipis SecvliT icvleba cvladis tipi. cvladis gansazRvra
xdeba sityviT var is aucileblad unda iyos gamoyenebuli
cvladebis aRwerisas an inicializaciisas. magaliTad,
var t1.
aq cvladis tipi ar aris gansazRvruli da is cnobili
gaxdeba mas Semeg rac mas mieniWeba mniSvneloba es ki xdeba
miniWebis operatoris saSualebiT. magaliTad:
var t1=345
am SemTxvevaSi t1 cvlads miniWebuli aqvs mniSvneloba 345.
cvladis mniSvneloba SeiZleba Seicvalos aseve miniWebis
operatoriT. miniWebis operatori SeiZleba gamoyenebuli iyos
nebismier adgilze da SeuZlia Secvalos ara marto monacemi
aramed cvladis tipic.
miniWebis operators aqvs saxe:
a=b
sadac a- cvladia, b- gamosaxuleba.
dasaSvebia cvladebis Semdebi aRwera:
var n=3245
var x=2.89
var p=true
var s=”gamoTvla damTavrebulia”
n da x cvladebs aqvT ricxviTi tipi, p-s aqvs logikuri
tipi, xolo s-s string.
JavaScript-Si gansazRvrulia aseve function tipi yvela
standartuli funqciisaTvis da aseve momxmareblis mier
gansazRvruli funqciebisaTvis.
JavaScript-Si obieqtebs aqvT monacemTa tipi object.
cvladebis moqmedebis are cvladebis moqmedebis are cvladebis moqmedebis are cvladebis moqmedebis are
JavaScript-Si arsebobs ori tipis cvladebi globaluri da
lokaluri. globaluri cvladi gansazRvrulia mTel
programaSi, lokaluri cvladi gansazRvrulia mxolod
konkretuli funqciis SigniT.
gamosaxuleba gamosaxuleba gamosaxuleba gamosaxuleba
gamosaxuleba Sedgeba literalebisagan, cvladebisagan,
moqmedebaTa niSnebisagan da frCxilebisagan. gamosaxulebis
gamoTvlis Semdeg miiReba erTi mniSvneloba, romelic SeiZ-
leba iyos ricxvi, striqoni, an logikuri.
gamosaxulebaSi arsebul yvela cvladi unda iyos gan-
sazRvruli. Tu gamosaxulebaSi arsebul romelime cvlads ar
aqvs mniSvneloba an ar aris gansazRvruli maSin xdeba
Secdomis dafiqsireba.
JavaScript-Si arsebobs null literali romelic aRniSnavs
ganusazRvrel mniSvnelobas.
nebismieri gamosaxuleba Sedgeba operandebis da opera-
ciis niSnebisagan. magaliTad, gamosaxuleba a*b -Si, a da b
operandebia, * operaciis niSania.
operaciebi arseboben unaruli (erTadgiliani) da bina-
ruli (oradgiliani). gamosaxuleba Caiwereba +A, Tu + - unaru-
li operaciis aRniSvnaa, an A+B. Tu + - binaruli operaciis
aRniSvnaa.
gamoTvlili mniSvnelobis mixedviT, gamosaxuleba SeiZ-
leba arsebobdes ariTmetikuli, logikuri da striqonuli.
ariTmetikuli gamosaxulebis Casawerad gamoiyeneba Sem-
degi operatorebi:
+ Sekreba
- gamokleba
* gamravleba
/ gayofa
% naSTis miReba gayofis Sedegad
++ operandis mniSvnelobis gazrda 1-iT
-- operandis mniSvnelobis Semcireba1-iT
operaciebis Sesruleba xdeba marcxnidan marjvniv ariT-
metikuli operaciebis prioritetis mixedviT.
JavaScrip-Si gamoiyeneba operatorebis Caweris Semoklebu-
li forma:
X+=Y X=X+Y
X-=Y X=X-Y
X*=Y X=X*Y
X/=Y X=X/Y
X%=Y X=X%Y
JavaScript-Si gamoiyeneba Sedarebis Semdegi operaciebi. isi-
ni Sesrulebis Sedegad iReben mxolod or mniSvnelobas true
Tu Sedareba WeSmaritia an false winaaRmdeg SemTxvevaSi. es
operaciebia:
< naklebia
<= naklebia an tolia
== tolia
!= ar aris toli
> metia
>= metia an tolia
! operacia (logikuri ara) gamoiyeneba logikuri tipis
operandebze. Tu a operandis mniSvneloba true, maSin !a – mniS-
vneloba aris mcdari, Tu a operandis mniSvneloba aris false ,
maSin !a - mniSvneloba aris WeSmariti. garda aRniSnulisa
logikuri operaciebis Sesasruleblad gamoiyeneba Semdegi
logikuri operaciebi:
&& (logikuri da), || (logikuri an)
maTi Sesrulebis Sedegi moyvanilia cxrilSi
A B A&&B A||B
true true true true
true false false true
false true false true
false false false false
striqonul mniSvnelobebze dasaSvebia konkatenciis (Seer-
Tebis) operacia. is aRiniSneba + niSniT.
magaliTad,
st1= “mimdinare”
st2=”mdgomareoba”
st3=st1+st2
an
st1+=st2
maSin st3 miiRebs mniSvnelobas “mimdinare mdgomareoba”
st1-ic miiRebs mniSvnelobas “mimdinare mdgomareoba”
JavaScript-Si gamoiyeneba Semdegi operatorebi (isini
mocemulia prioritetis Semcirebis mixedviT):
inkrementi ++
dekrementi --
uaryofa !
unaruli minusi -
gamravleba *
gayofa, gayofa naSTis SenaxviT /,%
gamokleba -
Sedareba <,>,<=,>=
toloba ==
ar aris toli !=
logikuri da &&
logikuri an ||
miniWeba +, +=, -=, *=, /=,
%=, !=
monacemTa tipebis gardaqmna monacemTa tipebis gardaqmna monacemTa tipebis gardaqmna monacemTa tipebis gardaqmna
monacemTa tipebi gavlenas axdens operatorebis Ses-
rulebaze, gansakuTrebiT maSin Tu operandebs aqvT sxvadasxva
tipi. aviRoT magaliTad ori ricxvis Sekrebis magaliTi
3+3 Sedegi iqneba 6,
magram roca operandebs sxvadasxva tipi aqvT
3+”3” Sedegi iqneba”33”
radgan meore operandis tipi aris striqonuli e.i Sedegi iqne-
ba striqonuli tipis. pirveli operandi avtomaturad gardaiqm-
neba striqonul tipad da Sedegad miiReba ori striqonis
gaerTianeba. Tu adgili eqneba aseT SemTxvevas:
3+3+”3” maSin Sedegi iqneba “63”.
JavaSkript enas aqvs SesaZlebloba striqonuli simboloebi
gardaqmnas ricxviT monacemebad. amisaTvis iyenebs funqciebs:
parselnt () da ParseFloat().
magaliTad:
parseInt (“34”) Sedegi iqneba 34
parseInt (“23.56”) Sedegi iqneba 23
e. i meore SemTxvevaSi Sedegis damrgvaleba moxdeba mTelamde.
ParseFloat(“42”) Sedegi iqneba 42
ParseFloat(“42.56”) Sedegi iqneba 42.33
rom gamoviyenoT es funqciebi iq sadac saWiroa gardaqmna
unda CavsvaT Sesabamisi funqcia.
magaliTad:
3+3+ parseInt”3” Sedegi iqneba 9.
ricxviTi mniSvnelobis gardavqmna striqonulad
ganvixiloT martiv magaliTebze:
(“”+2500) Sedegi iqneba2500
(“”+2500). length Sedegi iqneba 4.
length niSnavs rom daTvlili iqneba simboloebis
raodenoba. magaliTad, “2500” simboloebis raodenoba masSi
tolia 4-is. length - sigrZe , misi tipi aris ricxvi da
striqoni.
HTML dokumentSi programis Casma dokumentSi programis Casma dokumentSi programis Casma dokumentSi programis Casma
JavaScript-ze dawerili programa SeiZleba moTavsdes HTML
dokumentSi <script> da </script> tegebs Soris, Tu romelime tegi
gamorCenili iqneba programa ar gaiSveba.
<script> tegSi SeiZleba gamoviyenoT sxvadasxva paramet-
rebi, erT-erTi parametria language, romelic gansazRvravs
programis enas. JavaScript enisaTvis misi mniSvnelobaa “JavaScript”.
am atributis gamoyenebas aqvs saxe:
<script language=”JavaScript”>
<script> deskriptori SeiZleba moTavsebuli iyos yvelgan,
sadac saWiroa. zogjer sasurvelia da azri aqvs mis
moTavsebas Semdeg deskriptorebs Soris:
<HEAD> da </HEAD> an <BODY> da </BODY>.
zogierTi brauzeri ver igebeb HTML –is zogierT tegebs,
maSin xdeba maT mier aseTi tegebis ignorireba.
JavaScript-ze programebis dawerisas moxerxebulia gamoye-
nebuli iqnas komentarebis operatori. mas aqvs saxe <!-- . . . -->.
damxuravi tegis win ismeba // simbolo.
e.i
<script language=”JavaScript”>
<!--
JavaScript-enis operatorebi
//-->
</script>
SevadginoT marTkuTxa samkuTxedis farTobis gamosaTvle-
li programa, roca mocemulia misi kaTetebi
<HTML>
<HEAD>
<TITLE> pirveli programa</TITLE>
</HEAD>
<BODY>
<P> programa </P>
<script>
<!--
var a=8; b= 9
document.write(“marTkuTxa samkuTxedis farTobi
tolia”,a*b/2,”.”)
//-->
</script>
</P> programis dasasruli</P>
</BODY>
</HTML>
PprogramaSi gamoyenebulia ori cvladi a da b. HTML
gverdze gamotanis formirebisaTvis gamoiyeneba write document
obieqtSi
Tu JavaScript- s mxars ar uWers brauzeri, maSin gamoiyeneba
tegi <noscript>, es tegi moyveba <script> da </script> tegebs. Tu
brauzeri mxars uWers JavaScrip-s maSin es tegi ignorirdeba.
funqcia funqcia funqcia funqcia
programis Sedgenis dros gamoiyeneba logikurad damo-
ukidebeli nawilebi (qveprogramebi). programis yoveli nawili
SeiZleba davyoT calkeul qveprogramad. erTxel Seqmnili
programa SeiZleba gamoviyenoT mravaljer, bevr enaSi qveprog-
ramis gageba realizdeba procedurebis, funqciis, modulebis
da a.S daxmarebiT.
JavaScript-Si mTavari elementi aris funqcia.
funqcia esaa is samSeneblo bloki, romelic g funqcia esaa is samSeneblo bloki, romelic g funqcia esaa is samSeneblo bloki, romelic g funqcia esaa is samSeneblo bloki, romelic gamoiyeneba amoiyeneba amoiyeneba amoiyeneba
mravaljer mravaljer mravaljer mravaljer. .. .
funqciis aRweras aqvs saxe:
function F (V) {S}
sadac, F funqciis saxelia, romlis saSualebiTac xdeba
masze mimarTva, V- funqciis paramertebis (argumentebis) siaa,
isini erTmaneTisgan gamoiyofian mZimiT; s- funqciis tania, misi
saSualebiT moicema is Sesasrulebeli moqmedeba, romliTac
unda miviRoT Sedegi.
funqciis aRwerisas unda gaviTvaliswinoT, rom is ar
unda Seicavdes sxva funqciis aRweras.
Tu funqciis aRweras aqvs saxe:
function F (v1,v2, ... vn) {s}
maSin funqciis gamoZaxebas unda qondes saxe:
F (e1,e2, ... ,en)
sadac, e1,e2, ... en– gamosaxulebebia romlebic faqtiur
parametrebs (argumentebs) gansazRvraven.
v1,v2, ..., vn parametrebs, romlebic funqciis aRweraSi
aris miTiTebuli qvia formaluri parametrebi. Tu funqcias ar
aqvs parametrebi maSin mis aRweras aqvs saxe:
function F () {s}
frCxilebis arseboba gamoZaxebis operatorSi aucilebe-
lia anu funqciis gamoZaxebas aseT SemTxvevaSi eqneba saxe:
F ().
SeniSvna: yvela gansazRvra da funqcia unda Setanili
iyos <HEAD> ganyofilebaSi.
ganvixiloT marTkuTxa samkuTxedis farTobis gamoTvlis
programa funqciis gamoyeenebiT, rodesac mocemulia misi
kaTetebi.
<HTML>
<HEAD>
<TITLE> programa funqciis gamoyenebiT </TITLE>
<script language=”JavaScript”>
<!-- //
function ss (a,b)
{return a*b/2 }
// -->
</script>
</HEAD>
<BODY>
<P> furclis gamosaxva funqciiT</P>
<script>
<!- -
var a1=6; b1=9
var s= ss(a1,b1)
dokument.write (“miiReba mniSvneloba ”, s,”.”);
//-->
</script>
<P> furclis formirebis dasasruli </P>
</BODY>
</HTML>
funqciis tani Sedgeba mxolod erTi return operatoriT,
romelic gansazRvravs
funqciis gamoZaxeba xdeba funqciis tanSi miniWebis
operatoriT :
s=ss(a1,b1)
formalur a da b parametrs mieniWeba a1-is da b1-is faq-
tiuri mniSvneloba da Sesruldeba funqciis tani. miRebuli
mniSvneloba Tavsdeba dokumentSi Writen operatoriT.
ganxilul SemTxvevebSi momxmarebels ar qonda SesaZ-
lebloba Seetana mniSvnelobebi da mieRo Sesabamisi Sedegi.
formebi formebi formebi formebi
interaqtiuri dokumentebis umravlesoba (kavSiri Web
gverdsa da momxmarebels Soris) SeiZleba Seqmnili iyos
formebis saSualebiT. es is sadgilia sadac damalulia nebis-
mieri brauzeris interaqtiuri SesaZleblobebi: teqsturi veli,
Rilakebi, gadamrTvelebi, siebi da a.S..
momxmareblis moqmedeba (mag. mausis Rilakze daWera)
iwvevs garkveul process. am procesis damuSaveba xdeba for-
mebis elementebiT. procesis damuSavebeli parametris saxeli
iwyeba on TavsarTiT. magaliTad Click procesis damuSavebis
parametrs eqneba saxe onClick.
procesis parametrebi SeiZleba iyos operatorebi, pro
cesis mniSvnelobebi ki funqciis gamoZaxebebi, romlebic unda
Sesruldes rodesac es procesi gaaqtiurdeba.
davuSvaT gvsurs SevqmnaT forma romelSic fuZe da
simaRlis velebi gamoiyeneba Sesabamisi mniSvnelobis Sesata
nad. garda amisa formaSi SevqmnaT Rilaki gamoTvla. am Ri
lakze daWeriT miviRebT samkuTxedis farTobs. aseT SemTxveva
Si SeiZleba gamoyenebuli iyos Semdegi forma:
<FORM name=”form1”>
fuZe: <input type=”text” size=8 name=”st1”><hr>
simaRle: <input type=”text” size=8 name=”st2”><hr>
<input tupe=“button” value=gamoTvla
onClick=”maxval(document.form1.st1.value,
document.form1.st2.value,)”>
</FORM>
davweroT programa, romelic gamoTvlis samkuTxedis
farTobs da sawyisi mniSvnelobebis Sesatanad gamoviyenoT
forma.
<HTML>
<HEAD>
<TITLE> samkuTxedis farTobis gamoTvla formiT
</TITLE>
<script language=”JavaScript”>
<!-- //
function Fart(a,b)
{ var s=(a*b)/2;
document.write(“samkuTxedis farTobi aris”, s);
return s
}
// -->
</script>
</HEAD>
<BODY>
<p> samkuTxedis farTobis gamoTvla </P>
<FORM name=”form1”>
fuZe: <input type=”text” size=5 name=”st1”><hr>
simaRle: <input type=”text” size=5 name=”st2”><hr>
<input tupe=“button” value=gamoTvla
onClick=”Fart (document.form1.st1.value,
document.form1.st2.value,)”>
</FORM>
</BODY>
</HTML>
ganvixiloT Fart funqciis parametrebi dawvrilebiT.
HTML gverdis brauzeris mier interpretaciisas iqmneba
JavaScript-is obieqtebi. obieqtebs Soris urTierTkavSirs aqvs
ierarqiuli struqtura. ierarqiis yvelaze maRal doneze
imyofeba Windows obieqti, romelic brauzeris fanjaras
warmoadgens. is aris “mSobeli” yvela danarCeni obieqtis.
yvela furcels windows obieqtis garda aqvs document obieqti.
document obieqtis Tvisebebi gansazRvraven TviT dokumentis
Semcvelobas: fonis fers, Sriftis fers da a.S ganxilul
magaliTSi miRebuli forma warmoadgens document obieqtis
nakadebs, xolo formis yvela elementi warmoadgenen forma
obieqtis nakadebs. obieqtze miTiTeba xorcieldeba saxeliT,
romelic mocemulia Html tegis name parametriT. samkuTxedis
farTobis mniSvnelobis misaRebad unda Sesruldes is
konstruqcia romelic formis pirvel velSia Setanili:
document.form1.st1.value
formaze mimarTvisas SeiZleba ar iyos miTiTebuli
document obieqti. ganxilul magaliTSi formis pirveli
striqoni SeiZleba asec iyos Cawerili:
form1.st1.value
rodesac funqciaSi gadaicema martivi tipis monacemebi,
magaliTad ricxvebi, rogorc ganxilul magaliTSi,
parametrris mniSvnelobis gadacema xorcieldeba
mniSvnelobiT. a formalur parametrs eniWeba faqtiuri
parametris form1.st1.value mniSvneloba, xolo b formalur
parametrs form1.st2.value mniSvneloba. amis Semdeg sruldeba
funqciis tani.
situacia icvleba rodesac faqtiuri parametri aris
obieqti. am dros amboben parametris gadacema xorcieldeba
miTiTebiT an dasaxelebiT
pirobiTi operatori pirobiTi operatori pirobiTi operatori pirobiTi operatori if
mas aqvs saxe
if (piroba) {operatori an operatorebi}
if sagasaRebo sityvaa da misi miTiTeba aucilebelia.
operatori muSaobs Semdegnairad :
Tu mrgval frCxilebSi moTavsebuli piroba (misi
mniSvneloba logikuri tipisaa) WeSmaritia maSin Sesruldeba
figurul frCxilebSi Cawerili operatori an operatorebi,
Semdeg ki marTva gadaecema figuruli frCxilebis Semdeg Cawe-
ril operators. Tu piroba mcdaria maSin figurul
frCxilebSi Cawerili operatorebi ignorirdeba da marTva
gadaecema figuruli frCxilebis Semdeg Caweril operators.
pirobiTi operatori pirobiTi operatori pirobiTi operatori pirobiTi operatori if...else
mas aqvs saxe
if (piroba) {operatori an operatorebi} Tu
piroba WeSmaritia
else
{operatori an operatorebi} Tu
piroba mcdaria
magaliTi: ganvsazRvroT TebervalSi dReebis ricxvi imis
gaTvaliswinebiT weliadi Cveulebrivia Tu nakiani.
var febdays
var theYear=1993
if (theYear %4==0) { febdays=29}
else
{ febdays==28}
ganvixiloT JavaScript enaze programis Sedgenis ramdenime
magaliTi:
1. gamovTvaloT sam a, b, da c ricxvebs Soris
maqsimaluri mniSvneloba.
<HTML>
<HEAD>
<TITLE> maqsimaluri mniSvnelobis gamoTvla </TITLE>
<script language=”JavaScript”>
<!-- //
function max (obj)
{var a=Number (obj.num1.value);
var a=Number (obj.num2.value);
var a=Number (obj.num3.value);
var m=a
if (b>m) m=b
if (c>m) m=c
obj.res.value=m
}
// -->
</script>
</HEAD>
<BODY>
<H4>maqsimaluri mniSvnelobis gamoTvla </H4>
<FORM name=”form1”>
ricxvi 1: <input type=”text” size=8 name=”num1”><hr>
ricxvi 2: <input type=”text” size=8 name=”num2”><hr>
ricxvi 3: <input type=”text” size=8 name=”num3”><hr>
maqsimaluri mniSvneloba tolia
<input tupe=“button” value=gansazRvra onClick=”maxval(form1)”>
<input type =”text” size=8 name=”res”><hr>
<input type =”reset”>
</FORM>
</BODY>
<HTML>
2. SevadginoT programa romelic gamoiTvlis maqsimalur
da minimalur mniSvnelobebs sami ricxvidan.
<HTML>
<HEAD>
<TITLE> maqsimaluri da minimaluri mniSvnelobis
gamoTvla </TITLE>
<script language=”JavaScript”>
<!-- //
function maxmin (obj)
{ var a=Number (obj.num1.value);
var b=Number (obj.num2.value);
var ca=Number (obj.num3.value);
var l
var t
if (a>b) {l=b; t=a}
else
{t=b;l=a}
if(b>t) t=b
if(c<l) l=c
obj.resmax.value=t
obj.resmin.value=l
}
// -->
</script>
</HEAD>
<BODY>
<H4>maqsimaluri da minimaluri mniSvnelobis gamoTvla
</H4>
<FORM name=”form1”>
ricxvi 1: <input type=”text” size=8 name=”num1”><hr>
ricxvi 2: <input type=”text” size=8 name=”num2”><hr>
ricxvi 3: <input type=”text” size=8 name=”num3”><hr>
maqsimaluri mniSvneloba tolia
<input tupe=“button” value=gansazRvra onClick=”maxminval(form1)”>
<hr>
<input type =”text” size=8 name=”resmax”>maqsimaluri
mniSvneloba<hr>
<input type =”text” size=8 name=”resmin”>minimaluri
mniSvneloba<hr>
<input type =”reset”>
</FORM>
</BODY>
<HTML>
3. SevadginoT programa romelic mocemul oTx a,b,c, d
ricxvebs Ddaaalagebs zrdadobis mixedviT
algoriTmi algoriTmi algoriTmi algoriTmi: Tavidan edareba ori a da b cvladebis
mniSvnelobebi. Tu a meti aRmoCndeba b-ze cvladebi cvli-
an mniSvnelobebs, Semdeg a-s mniSvneloba dardeba c-s. Tu
a>c-ze maSin cvladebi kvlav icvlian mniSvnelobebs. da
bolos aedareba d-s, saWiroebis SemTxvevaSi kvlav xdeba
cvladebis mniSvnelobebis Secvla. aseTnairad miiReba
rom a-s mniSvneloba 4-dan aris minimaluri. Semdeb b eda-
reba c da d-s saWiroebisas cvladebi cvlian mniSvnelo-
bebs. bolos c edareba d-s.
<HTML>
<HEAD>
<TITLE>oTxi ricxvis mniSvnelobis dalageba</TITLE>
<script language=”JavaScript”>
<!-- //
function maxmin (obj)
{ var a=Number (obj.num1.value);
var b=Number (obj.num2.value);
var c=Number (obj.num3.value);
var d=Number (obj.num3.value);
if (a>b) {r=a; a=b; b=r}
if (a>c) {r=a; a=c;c=r}
if(a.d){r=a;a=d;d=r}
if (b>c) {r=b;b=c;c=r}
if (b>d){r=b;b=d; d=r}
if (c>d){r=c; c=d; d=r}
obj.num1.value=a
obj.num2.value=b
obj.num3.value=c
obj.num4.value=d
}
// -->
</script>
</HEAD>
<BODY>
<H4> oTxi ricxvis mniSvnelobis dalageba zrdadobis
mixedviT </H4>
<FORM name=”form1”>
ricxvi 1: <input type=”text” size=10 name=”num1”><hr>
ricxvi 2: <input type=”text” size=10 name=”num2”><hr>
ricxvi 3: <input type=”text” size=10 name=”num3”><hr>
ricxvi 4: <input type=”text” size=10 name=”num4”><hr>
maqsimaluri mniSvneloba tolia
<input tupe=“button” value=dalageba onClick=”sortval(form1)”> <hr>
<input type =”reset” value= gasufTaveba>
</FORM>
</BODY>
<HTML>
ciklebi ciklebi ciklebi ciklebi
ciklebi aRniSnavs gansazRvruli moqmedebebis ganmeore
biT Sesrulebas, manam sanam ar Sesruldeba garkveuli piroba.
JavaScript –Si yvelaze xSirad gamoyenebadi cikluri
struqtura aris for. mis sintaqss aqvs Semdegi saxe:
for ([sawyisi mniSvneloba]; [piroba]; [cvlilebis biji])
{ciklis SigniT Sesasrulebeli operatorebi
}
kvadratuli frCxilebi miuTiTebs rom maTSi Cawerili
operatorebi ar arian aucilebeli rom iqnan Setanili
sawyisi mniSvneloba- gansazRvravs ciklis mTvlelis saw-
yis mniSvnelobas;
piroba- igulisxmeba iseTive gamosaxuleba rogorc if ope-
ratorSi.
cvlilebis biji- warmoadgens operators, romelic srul-
deba yoveljerze ciklis SigniT Sesasrulebeli operatorebis
Sesrulebis Semdeg.
masivebi masivebi masivebi masivebi
JavaScript-Si monacemTa Senaxvis da organizaciis erT-erTi
yvelaze moxerxebuli xerxia masivi. yvelaze martivi masivi
SeiZleba warmovidinoT erTganzomilebiani cxrilis saxiT.
aseTi cxrilis TiToeuli sveti Seicavs monacemebs., amitom
TiToeuli sveti danomrilia. svetebis danomrisaTvis ( masivis
elementebis) gamoiyeneba mkacrad gansazRvruli ricxviTi
Tanmimdevroba, pirvel svets aqvs nulovani nomeri. svetebis am
nomrebs zogjer uwodeben indeqsebs. masivis elementze mimar-
TvisaTvis saWiroa masivis saxeli da misi indeqsis saxeli.
masivis elementebi SeiZleba iyos nebismieri tipis, maT
Soris obieqtebic. JavaScript-Si erTi masivis elementebi SeiZ-
leba iyos sxvadasxva tipis monacemebi.
masivi ganisazRvreba cvladis saSualebiT. amitom masivis
Seqmnisas cvlads eniWeba axali masivis obieqti. masivebi
warmoadgenen JavaScript-Si obieqtebs..
masivis gamosacxadeblad gamoiyeneba specialuri sityva
new. misi saSualebiT mexsierebaSi masivis elementebisaTvis
gamoiyofa adgili. mas aqvs araaucilebeli parametri Array (),
romelSic SeiZleba miTiTebuli iyos masivis elementebis
saorientacio raodenoba. magaliTad
var USS = new Array (51)
am aRweris Sedegad masivisaTvis mexsierebaSi gamoiyofa
adgili 51 elementisTvis. rom Seivsos masivi mis yovel
elements unda mivaniWoT mniSvneloba. masivis elementze
mimarTvisaTvis gamoiyeneba specialuri indeqsebi, Tavidan
iwereba masivis saxeli, Semdeg kvadratul frCxilebSi saWiro
elementis indeqsi. USS masivis pirveli elementi iqneba:
USS[0].
}
kvadratuli frCxilebi miuTiTebs rom maTSi Cawerili
operatorebi ar arian aucilebeli rom iqnan Setanili
sawyisi mniSvneloba- gansazRvravs ciklis mTvlelis saw-
yis mniSvnelobas;
piroba- igulisxmeba iseTive gamosaxuleba rogorc if ope-
ratorSi.
cvlilebis biji- warmoadgens operators, romelic srul-
deba yoveljerze ciklis SigniT Sesasrulebeli operatorebis
Sesrulebis Semdeg.
masivebi masivebi masivebi masivebi
JavaScript-Si monacemTa Senaxvis da organizaciis erT-erTi
yvelaze moxerxebuli xerxia masivi. yvelaze martivi masivi
SeiZleba warmovidinoT erTganzomilebiani cxrilis saxiT.
aseTi cxrilis TiToeuli sveti Seicavs monacemebs., amitom
TiToeuli sveti danomrilia. svetebis danomrisaTvis ( masivis
elementebis) gamoiyeneba mkacrad gansazRvruli ricxviTi
Tanmimdevroba, pirvel svets aqvs nulovani nomeri. svetebis am
nomrebs zogjer uwodeben indeqsebs. masivis elementze mimar-
TvisaTvis saWiroa masivis saxeli da misi indeqsis saxeli.
masivis elementebi SeiZleba iyos nebismieri tipis, maT
Soris obieqtebic. JavaScript-Si erTi masivis elementebi SeiZ-
leba iyos sxvadasxva tipis monacemebi.
masivi ganisazRvreba cvladis saSualebiT. amitom masivis
Seqmnisas cvlads eniWeba axali masivis obieqti. masivebi
warmoadgenen JavaScript-Si obieqtebs..
masivis gamosacxadeblad gamoiyeneba specialuri sityva
new. misi saSualebiT mexsierebaSi masivis elementebisaTvis
gamoiyofa adgili. mas aqvs araaucilebeli parametri Array (),
romelSic SeiZleba miTiTebuli iyos masivis elementebis
saorientacio raodenoba. magaliTad
var USS = new Array (51)
am aRweris Sedegad masivisaTvis mexsierebaSi gamoiyofa
adgili 51 elementisTvis. rom Seivsos masivi mis yovel
elements unda mivaniWoT mniSvneloba. masivis elementze
mimarTvisaTvis gamoiyeneba specialuri indeqsebi, Tavidan
iwereba masivis saxeli, Semdeg kvadratul frCxilebSi saWiro
elementis indeqsi. USS masivis pirveli elementi iqneba:
USS[0].
[Pasuxi][Cit]|