Txoj hauv kev los tsim kev cuam tshuam zoo ntawm cov nplooj ntawv web yog los ntawm kev siv cov neeg siv cov ntawv sau sab. Lawv yog cov ntawm cov code uas tau txhais los ntawm lub cav scripting ntawm daim ntawv thov tso tawm cov ntaub ntawv. JavaScript yog lus nrov ua programming siv rau scripting. Txhawm rau kom tsab ntawv tuaj yeem ua tiav, nws yuav tsum muab tso rau hauv cov ntawv hauv qee txoj kev.
Nws yog qhov tsim nyog
- - tsab ntawv code;
- - qhov chaw ntawv;
- - cov ntawv nyeem editor.
Cov Lus Qhia
Kauj ruam 1
Txiav txim siab txoj kev zoo tshaj plaws los ntxig tsab ntawv. Yog tias nws tau xav tias tib tsab ntawv yuav siv rau hauv cov ntawv sib txawv, tom qab ntawd nws ua rau muaj kev nkag siab nws txav mus rau lwm cov ntaub ntawv sab nraud thiab txuas nws los ntawm qhov ntawd. Txwv tsis pub, nws tsim nyog rau sau cov ntawv sau hauv lub cev ntawm nplooj. Yog hais tias qhov loj ntawm tsab ntawv yog qhov loj, nws tsim nyog muab nws tso rau hauv nyias daim nyias nyias sau rau hauv daim ntawv. Yog tias qhov program code tau me me hauv qhov ntim thiab ua qhov tshuaj tiv thaiv rau ib qho xwm txheej twg, nws raug tso cai tso rau hauv qhov kev ntaus nqi uas txhais lub ntsiab lus tsim cov khoom tsim los yog href attribute ntawm qhov txuas.
Kauj ruam 2
Muab cov ntawv sau los ntawm cov khoom siv sab nraud. Ntxiv SCRIPT keeb nrog kev tso cai pom meej thiab ntaus cov khoom rau hauv daim ntawv lub cev lossis ntu HEAD. Piv txwv li, koj tuaj yeem ua nws zoo li no: Tus nqi ntawm src attribute yuav tsum yog URI taw rau cov kev pab cuam los ntawm cov ntawv sau cov lus sau. Nws qhia tau tias qhov muab tau los ntawm tsab ntawv lus. Tab sis yog tias nws raug rho tawm, tus nqi encode yuav raug coj los ua qhov txiaj ntsig ntawm cov ntawv sau rau hauv tsab ntawv uas ntxig.
Kauj ruam 3
Ntxig tsab ntawv rau hauv cov ntawv ntawm nplooj ntawv. Siv SCRIPT caij nrog cov ntawv sau sab hauv. Piv txwv li, nws yuav zoo li no:
ceev faj ("Tsab ntawv ua haujlwm zoo!");
Cov lus HTML uas muab sau cov cai no yuav tsum muaj kev sib raug zoo nrog cov browsers qub. Koj tuaj yeem siv cov lus XML hauv XHTML cov ntaub ntawv.
Kauj ruam 4
Ntxig javascript code rau hauv inline event handlers. Tshawb nrhiav qhov keeb kwm hauv cov ntawv uas nws xav ua haujlwm. Ntxiv rau ib qho cwj pwm uas txhais tau qhov tsim nyog daws. Piv txwv, tus cwj pwm uas qhia meej qhov handler rau nas nyem rau ib qho khoom yog onclick, tus tuav rau qhov poob ntawm kev tsom xam yog onblur, thiab tus yuam sij keystroke handler yog onkeydown.
Kauj ruam 5
Ntaus cov ntawv cim raws li cov ntawv sau uas qhia meej txog tus nqi ntawm yam ntxwv ntxiv. Piv txwv li, txhawm rau tso tawm ib tsab xov thaum lub DIV caij raug nyem nrog nas, koj tuaj yeem siv kev tsim kho hauv qab no: Cov ntawv sau ua lus Nco ntsoov tias txhawm rau txhais cov hlua ntawm txoj hauv kev inline element handler code, koj yuav tsum siv hom lus txawv dua li cov uas qhia kom meej tus nqi ntawm cov cwj pwm HTML …
Kauj Ruam 6
Ntxiv cov tsab ntawv rau href keeb ntawm qhov txuas. Tus nqi href yuav tsum yog qhov URL, tus qauv piav qhia ntawm uas yog "javascript:", thiab feem chaw nyob yog qhov hais tawm uas siv tau. Piv txwv li: Txuas kab ntawv Yog tias koj xav siv ntau cov kab lus, siv cov lus hais tawm uas tau txiav txim siab los ntawm kab ntawv {thiab}.