Yuav Ua Li Cas Los Ua Cov Ntawv Sau

Cov txheej txheem:

Yuav Ua Li Cas Los Ua Cov Ntawv Sau
Yuav Ua Li Cas Los Ua Cov Ntawv Sau

Video: Yuav Ua Li Cas Los Ua Cov Ntawv Sau

Video: Yuav Ua Li Cas Los Ua Cov Ntawv Sau
Video: Qhia kho kom xov tooj muaj zog tiag tiag2020 2024, Hlis ntuj nqeg
Anonim

Hauv kev siv Internet, nws yog ib qho tsim nyog los txuas rau qee yam kev ua yeeb yam rau virtual los ua cov kev coj ua uas tsim nyog rau tus programmer hauv qhov browser lossis ntawm lub server. Kev nqis tes ua tuaj yeem yog, piv txwv, pom cov teebmeem lossis kev ua tiav ntawm cov ntaub ntawv nkag los ntawm tus qhua hauv qhov browser. Los yog sib sau ua ke cov nplooj ntawv thov los ntawm cov thaiv nyias nyob ntawm tus neeg rau zaub mov. Tus tswj hwm virtual ntawm cov kev nqis tes ua yuav yog lub server lossis browser software, thiab cov ntawv sau rau cov neeg ua haujlwm yuav tsum tau sau ib qho ntawm cov scripting cov lus programming. Kom tau txais ib lub tswv yim dav dav ntawm yuav ua li cas sau ntawv, cia sau ib tsab ntawv yooj yim hauv JavaScript.

Yuav ua li cas los ua cov ntawv sau
Yuav ua li cas los ua cov ntawv sau

Cov Lus Qhia

Kauj ruam 1

JavaScript tau tua ncaj qha hauv qhov browser, yog li txhua yam koj yuav tsum sau thiab coj ua twb dhau ntawm koj lub khoos phis tawm lawm. Ua cov cuab yeej ua haujlwm rau cov programmer, peb yuav siv cov ntawv nyeem ib txwm ua dhau los - Tus qauv Notepad. Qhov no yog qhov tsim nyog rau kev tsim cov ntawv sau yooj yim, tab sis, ntawm qhov tseeb, rau qhov kev zov me nyuam tas li nws zoo dua yog siv tus kws sau ntawv tshwj xeeb.

Kauj ruam 2

Tam sim no koj tuaj yeem pib sau cov kab kev qhia. Qhov browser nkag siab ntau dua ib hom lus - piv txwv li, HTML (HyperText Markup Language) yog siv los khij ib nplooj ntawv, thiab Cascading Style Sheets (CSS) yog siv los piav cov ntsej muag ntawm cov nplooj ntawv txuas ntxiv. Txhawm rau qhia tus neeg sau ntawv paub tias qhov no ntawm nplooj ntawv nplooj ntawv sau yog hauv JavaScript, tag nrho cov lus qhia yuav tsum muab tso rau sab hauv qhov qhib thiab kaw cov cim npe:

Cov lus qhia rau qhov browser yog hu ua cov neeg ua haujlwm lus. Piv txwv li, cov lus qhia kom nyeem thiab nco qab hnub tim thiab sijhawm ntawm lub khoos phis tawm rau siv tom qab ntawv sau zoo nkaus li qhov no: var aTime = tshiab Hnub (); Tam sim no aTime kwv muaj cov hnub thiab sij hawm cov ntaub ntawv thiab tuaj yeem muab rov qab thiab ua yog tias tsim nyog. Lwm cov lus qhia - kom luam tawm qee cov lus hauv lub cev ntawm nplooj ntawv - zoo li qhov no: document.write ("qee cov lus"); Ua tib zoo mloog - ntawm no ib qho khoom muaj npe "cov ntawv" tau teev, nws tsis tas yuav tsim, qhov no muaj li ntawd. Nws yog daim duab virtual ntawm nplooj ntawv tam sim no. Los ntawm cov khoom no, koj tuaj yeem rho tawm cov ntaub ntawv hais txog nplooj ntawv thiab koj tuaj yeem ua ntau yam hloov nrog nws - piv txwv li, nyob hauv kab ntawv kab lus no, koj tau sau cov lus "txhua cov lus" rau daim ntawv siv cov lus sau. Tam sim no siv ob qho no kab hauv tsab ntawv - sau lub sijhawm tam sim no ntawm nplooj ntawv: document.write ("Lub sijhawm tam sim no" + aTime.getHours () + ":" + aTime.getMinutes ()); Ntawm no, nrog ib qho yooj yim ntxiv (+), koj concatenate plaub ntu ntawm cov hlua luam tawm. Thaum ua tiav, koj tsab ntawv yooj yim yuav zoo li no:

var aTime = tshiab Hnub ();

daim ntawv sau. Qhov chaw ("Lub sijhawm tam sim no" + aTime.getHours () + ":" + aTime.getMinutes ());

Kauj ruam 3

Cov kauj ruam kawg: txuag cov ntawv sau nrog cov html lossis htm txuas ntxiv (piv txwv li, timeJS.html). Txhawm rau pom qhov koj tau txais, qhib cov ntaub ntawv hauv koj lub browser - tsuas yog ob npaug-nias nws.

Pom zoo: