I-15 yamaSampula Esampula YeSampula Ye-JavaScript yamaWebhusayithi akho

JavaScript kuyinto isetshenziswe yonke indawo online kulezi zinsuku – ukwenza ngcono ukuxhumana kwewebhusayithi, ukuqinisekisa imininingwane, kanye / noma ukuthuthukisa ukuphuma kwewebhusayithi.


IJavaScript ir labs okokuqala kwi-1995 futhi ifike kude kusukela lapho ngokwemigomo yokwamukelwa nokuthi isetshenziswa kanjani. I-sintakse esetshenziswe kuJavaScript yathonywa ngokuqinile yi-C; kodwa iJava, Pearl, Python, ne-Scheme nayo nayo yadlala indima yayo.

Izeluleko Zokuqala zeJavaScript: Okudingayo Ukuze Ukwazi?

Okokuqala, izinto eziyisisekelo ezimbalwa okudingeka wazi:

  • I-JavaScript ir pieejams visur
  • I-JavaScript izosebenza njalo lapho ikhasi lilayishwa
  • I-JavaScript tas ir personhathi ukulayisha ngokuxhumeka kwe-Intanethi
  • I-JavaScript isasuka kumakhasi e-cached
  • Ungabamba i-JavaScript ngaphakathi kwekhasi lewebhu noma ngaphandle kwefayela le-.js
  • I-Javascript ihluke ngokuphelele kuneJava

Kubalulekile futhi ukuqonda ukuthi iJavaScript empeleni izokuholela enhlekeleleni uma isetshenziswa ngendlela activfanele.

Amakheli we-JavaScript akhiwe kahle futhi anobuhlakani azonciphisa iwebhusayithi yakho futhi alimaze ukuzulazula jikelele kwesayithi. Lokhu nakho kuthinta inani lokubuya kwezivakashi zakho (ngenxa yolwazi lomsebenzisi olubi) kanye namazinga ezinjini zokusesha (ngenxa yamanani wokuphendula wewebhusayithi aphambili kanye nokukhasa kwe-bot). Ukusiza ukuqinisekisa icala lami lapha, zifake ezicathulweni zokubuka. Uma iwebhusayithi oyivakashele ilayishe kancane, bekunzima ukuyisebenzisa, futhi, ukungavezi – ngabe ubuyela kusayithi? Ngeke.

Ngezansi kunohlu oluncane lwezinto okufanele ucabange ngazo lapho ungeza iJavaScript kuyo iwebhusayithi yakho.

  • Ingabe i-JavaScript idinga ukuthi isayithi isebenze kahle?
  • Isayithi lizobonakala kanjani uma i-JavaScript ivinjelwe?
  • I-JavaScript izolimaza ukusebenza kweseva?
  • Ingabe uzongeza ukusiza kwe-JavaScript ukuhambisa isayithi lakho ngendlela ofuna ukuyifaka ngayo?

Ča, angizami ukukusabisa ngala maphuzu.

Eqinisweni, ungesabi Sebenzisa iJavaScript kuwebhusayithi yakho njengoba ihlinzeka ngezinzuzo zamathani futhi, njengoba kushiwo, isetshenziswa ezinkulu. Iphuzu eliyisihluthulelo engizama ukulifinyelela lapha akuyona nje ukuqhubeka unezela izici zeJavaScript kusayithi lapho kungenasidingo khona. Amanye amasayithi azodinga iJavaScript enkulu kunamanye; ezinye zidinga okuncane nje – Ukuthi isayithi eyodwa iyayenza akusho ukuthi nawe kufanele wenze okufanayo.

I-Freebies: I-15 Jauns I-JavaScript Imiklamo Yewebhusayithi Yakho

Manje, ake sehle kulokho okufike lapha – ngezansi uhlu lwama-snippets e-15 JavaScript azothuthukisa isayithi lakho ngokusebenza noma ukubukeka. Ikhodi izophulwa ibe yizingxenye ezimbili, ikhanda nomzimba noma ifayela le- .js. Uma kunganikezwa isihloko sesigaba ngakho-ke asidingeki kuleso slathi esithile.

I-1. Ukuqonda ividiyo ye-HTML5

Isampula esheshayo

umsebenzi uyaqonda_video () {Atgriezties !! document.createElement (‘video’). canPlayType; // Būla} uma (! ukuqonda_video ()) {// Kufanele kube yisipheqululisidala noma i-IE. // Mhlawumbe jena efana nokufihla izilawuli // HTML5 Izilawuli. Noma yini … videoControls.style.display = ‘nav’; }

Jenzani i-JavaScript fragments?

Le fragments encane izokuvimbela iwebhusayithi yakho ukuthi izame ukubonisa ividiyo isiphequluli esinakukwazi ukusekela, ukulondoloza amandla omgwaqo kanye nokucubungula amandla.

I-2. Amakhuki weJavaScript

Isampula esheshayo

/ ** * Imisa ikhukhi ngegama elinikeziwe nenani. * * Igama Igama le-cookie * Inani le-cookie * [liphelelwa yisikhathi] Isikhathi sokuphelelwa kukhukhi (okuzenzakalelayo: ukuphela kweseshini yamanje) * [indlela] Indlela lapho ikhukhi isebenza khona] Ohazenzalele ((šajāzakalelayo: isizinda sedokhumenti yokushayela) * [evikelekile] Inani le-Boolean elibonisa uma ngabe ukuhanjiswa kukhukhi kudinga ukuhanjiswa okuphephile * / ukusebenza setCookie (igama, inani, ukuphelelewa isikuaki) + "=" + ukuphunyuka (inani) + ((kuphelelwa isikhathi)? "; kuphelelwa isikhathi =" + derīguma termiņš.toGMTSstring (): "") + ((indlela)? "; indlela =" + indlela: "") + ((isizinda)? "; domēns =" + domēns: "") + ((kuvikelekile)? "; kuvikelekile": ""); } / ** * Ithola inani le-cookie echaziwe. * * Igama Igama le-cookie oyifunayo. * * Ibuyisa intambo equkethe inani lekhukhi echaziwe, * noma i-null uma ikhukhi lingekho. * / funkcija GetCookie (igama) {var dc = document.cookie; var prefikss = igama + "="; var qala = dc.indexOf (";" + isiqalo); uma (qala == -1) {qala = dc.indexOf (isiqalo); uma (qala! = 0) buyela null; } okunye {qala + = 2; } var end = document.cookie.indexOf (";", qala); uma (ukuphela == -1) {beigas = dc.length; } pirkt ubuwena (dc.substring (qala + prefikss.garums, beigas)); } / ** * Unamathisela ikhukhi elibekiwe. * * Igama legama le-cookie * [indlela] yendlela yekhukhi (kumele ifane nendlela esetshenziselwa ukudala ikhukhi) * sīkfaila domēns (kumele ilingane nesizinda esisetshenziselwe ukudala ikhukhi) * / funkcija DeleCookie (igama, (GetCookie (igama)) {document.cookie = igama + "=" + ((indlela)? "; ceļš =" + indlela: "") + ((domēns)? "; isizinda = "+ domēns:" ") +"; derīguma termiņš beidzas = Ceturtdien, 01.-Jan – 70 00: 00: 01 GMT "; }}

Jenzani i-JavaScript fragments?

Le fragments isikhashana kodwa iwusizo kakhulu, izovumela isayithi lakho ukuthi ligcine ulwazi kwikhompyutha yombukeli bese lifunda kwelinye iphuzu ngesikhathi. Le fragments ingasetshenziswa ngezindlela eziningi ezahlukene zokufeza imisebenzi ehlukile.

I-3. Layisha kuqala izithombe zakho

Isampula esheshayo

izithombe ze-var = i-Array entsha (); i-preloadImages () {ye (i = 0; i

Jenzani i-JavaScript fragments?

Le fragments izovimbela isayithi lakho ukuthi lingabi nesikhathi esibucayi lapho ibonisa kuphela ingxenye yesayithi; Lokhu akukona nje kubukeka kubi kodwa futhi akusizi ngalutho. Konke okumele ukwenze wengeze izithombe zakho esigabeni sokulayisha kuqala futhi ulungele ukugoqa.

I-4. Ukuqinisekiswa kwe-imeyili

Isampula esheshayo

Inhloko:

umsebenzi uqinisekisaEmail (theForm) {if (/ ^ w + audiotaurwa-> /.test(theForm.email-id.value)) {pirkt (iqiniso); isexwayiso ("Ikheli le-imeyili elingavumelekile! Sicela ufake futhi ngokucophelela !."); buyela (ngamanga); }

umzimba: Ikheli le-imeyili:

Jenzani i-JavaScript fragments?

Īss fragments izokuqinisekisa ukuthi ikheli le-imeyili elifomethwe kahle lifakwe kwifomu, alinakuqinisekisa ukuthi ikheli le-imeyili langempela, akukho ndlela yokukuhlola lokho ngeJavacript.

I-5. Akukho Qhafaza kwesokudla

Isampula esheshayo

umsebenzi f1 () {uma (amaphepha.all) {buyela amanga; }} sebenza f2 (e) {if (document.layers ||) (document.getElementById &! document.all)) {if (e.which == 2 || e.which == 3) {buyela amanga; }}} uma (document.layers) {imibhalo.captureEvents (Umcimbi.MOUSEDOWN); idokhumenti.onmousedown = f1; } okunye {document.onmouseup = f2; umqulu.oncontextmenu = f1; } idokhumenti.oncontextmenu = umsebenzi omusha ("buyisa amanga");

Jenzani i-JavaScript fragments?

Le fragments izovimbela umbukeli ukuba akwazi ukuchofoza ngakwesokudla ekhasini lakho. Lokhu kunganciphisa umsebenzisi ojwayelekile ukuboleka izithombe noma ikhodi kusuka kusayithi lakho.

I-6. Khombisa Izingcaphuno ezingekho emthethweni

Isampula esheshayo

Galva: bhalaRandomQuote = umsebenzi () {var citēt = masīvs entsha (); izingcaphuno [0] = "Isenzo yisilinganiso sangempela sobuhlakani."; izingcaphuno [1] = "Es beisbola inenzuzo enkulu phezu kwekhilikithi yokuthi isheshe iphele."; izingcaphuno [2] = "Yonke inhloso, yonke isenzo, yonke imicabango, nakho konke ukuzwa, ngabe kukaziwa noma kungaziwa, ngumzamo wokukhulisa izinga lokuthula kwengqondo."; izingcaphuno [3] = "Inhloko enhle nenhliziyo enhle zihlala ziyinhlanganisela ebabazekayo."; var rand = Math.floor (Math.random () * izingcaphuno.length); umqulu.write (izingcaphuno [zamarandi]); } bhalaRandomQuote ();

umzimba: bhalaRandomQuote ();

Jenzani i-JavaScript fragments?

Kulungile lokhu akusiyo ishidi ukuthi zonke izingosi zingasebenzisa kodwa zingasetshenziswa ukubonisa okungaphezulu nje kokucaphuna okungahleliwe. Ungashintsha okuqukethwe ok izingcaphuno kunoma yini oyifunayo futhi ube nezithombe ezingahleliwe noma umbhalo oboniswe noma kuphi kusayithi lakho.

I-7. Izixhumanisi Zangaphambilini / Ezilandelayo

Isampula esheshayo

Ikhasi langaphambilini | Ikhasi elilandelayo

Jenzani i-JavaScript fragments?

Le snippet inkulu uma unamakhasi amaningi ku-athikili noma kusifundo. Izovumela umsebenzisi ukuthi upheqa phakathi kwamakhasi kalula. Kuyinto encane futhi isisindo esincane esivela endaweni yokubuka.

I-8. Beka i-grāmatzīmju ekhasini

Isampula esheshayo

Jenzani i-JavaScript fragments?

Le snippet izovumela umsebenzisi ukuthi azimise ikhasi lakho kalula; konke okumele bakwenze ukuchofoza isixhumanisi. Izici zayo ezincane ezifana nalokhu ezingandisa ababukeli bakho ulwazi jikelele.

I-9. Isixhumanisi Esilula Sekhasi Lephepha

Isampula esheshayo

Ikhasi Lokuphrinta

Jenzani i-JavaScript fragments?

Lesi sixhumanisi esincane sizovumela imibono yakho ukuba iphrinta kalula ikhasi lakho. Isebenzisa isici sokuphrinta esheshayo sesivele sisethiwe ngesiphequluli sakho futhi asisebenzisi izinsiza kuze kuchofozwe.

I-10. Khombisa usuku oluhleliwe

Isampula esheshayo

Galva: parādīt showDate () {var d = usuku olusha (); var curr_date = d.getDate (); var curr_month = d.getMonth () + 1; // izinyanga nulles nulles curr_year = d.getFullYear (); umqulu.write (curr_date + "-" + curr_month + "-" + curr_year); }

umzimba: showDate ();

Jenzani i-JavaScript fragments?

Le fragments izokuvumela ukuba ubonise usuku lwamanje noma kuphi ekhasini lakho lewebhu futhi akudingeki libuyekezwe. Mane nje uyibeke endaweni futhi ukhohlwe ngakho.

I-11. Isihlukanisi seComma

Isampula esheshayo

Galva: i-funkcija addCommas (inombolo) {num + = ”; var n1 = inombolo.split (‘.’); var n2 = n1 [0]; var n3 = n1.length> 1? ‘.’ + n1 [1]: ”; var temp = / (d +) (d {3}) /; ngenkathi (temp.test (n2)) {n2 = n2.aizstāt (temp, ” + ‘,’ + ”); } var out = atgriešanās n2 + n3; umqulu.bhala (ngaphandle); }

umzimba: i-addCommas ("4550989023");

Jenzani i-JavaScript fragments?

Le fragments ingasetshenziswa ikakhulukazi amasayithi asebenzisa izinombolo kaningi. Le fragments izogcina izinombolo zakho zibukeka ezifanayo ebhodini. Konke okumele ukwenze ukukopisha umugqa womzimba lapho ufuna ukwengeza khona inombolo bese ushintsha inombolo lapho ngenombolo yakho.

I-12. Thola Indawo Yokubonisa Yesiphequluli

Isampula esheshayo

Ububanzi besikhathi sakho sokubuka ngu ‘+ skata joslas platums +’ x ‘+ skata lauka augstums +’

‘); // ->

Jenzani i-JavaScript fragments?

Le fragments izokuvumela ukuthi uthole ububanzi nokuphakama kwendawo yokubonisa kusiphequluli sakho sokubukwa. Lokhu kuzonikeza umklami ikhono lokudala nokusebenzisa izibonisi ezahlukene ngokususelwa kusayizi wesiphequluli sesiphequluli somsebenzisi.

I-13. Phinda uqondise kabusha ngokubambezeleka kokukhetha

Isampula esheshayo

setTimeout ("windows.location.href = ‘http://walkerwines.com.au/’", 5 * 1000);

Jenzani i-JavaScript fragments?

Le fragments izokuvumela ukuba uqondise kabusha ababukeli bakho kwenye ikhasi futhi unendlela yokubeka ukulibaziseka. Ukusetshenziswa kwalesi fragments kuyinto enhle ozichaza futhi kuyithuluzi eliwusizo kakhulu ukuba babe ebhande lakho.

I-14. Tola ama-iPhones

Paraugs

uma ((navigator.userAgent.match (/ iPhone / i))) || (navigator.userAgent.match (/ iPod / i)) {if (document.cookie.indexOf ( "iphone_redirect = amanga") == -1) {windows.location = "http://m.espn.go.com/wireless/?iphone&i = COMR"; }}

Jenzani i-JavaScript fragments?

Izgriezuma fragmenta izkuvumela ukuba ubone ukuthi umbukeli wakho izmantošana-iPhone noma i-iPod evumela ukuthi ubonise okuqukethwe okuhlukile kubo. Lo mdlalo uzuzisa kakhulu kangakanani ukuthi imakethe yeselula ikhulu kangakanani futhi uzoqhubeka ukhula.

I-15. Phrinta Umlayezo ku-Isimo Bar

Isampula esheshayo

“; // ->

Jenzani i-JavaScript fragments?

Le fragments encane izokuvumela ukuthi uphrinte umlayezo kubha yomumo. Ungabonisa izindaba zakamuva noma ezibalulekile endaweni ezobamba iso lomsebenzisi.

Jeffrey Wilson Administrator
Sorry! The Author has not filled his profile.
follow me
    Like this post? Please share to your friends:

    I-15 yamaSampula Esampula YeSampula Ye-JavaScript yamaWebhusayithi akho

    JavaScript kuyinto isetshenziswe yonke indawo online kulezi zinsuku – ukency ngcono ukuxhumana kwewebhusayithi, ukuqinisekisa imininingwane, kanye / noma ukuthuthukisa ukuphuma kwewebhusayithi.


    IJavaScript ivele okokuqala kwi-1995 futhi ifike gestion kusukela lapho ngokwemigomo yokwamukelwa nokuthi isetshenziswa kanjani. I-Sintaxa esetshenziswe kuJavaScript yathonywa ngokuqinele yi-C; kodwa iJava, Pearl, Python, ne-Scheme nayo nayo yadlala indima yayo.

    Izeluleko Zokuqala zeJavaScript: Okudingayo Ukuze Ukwazi?

    Okokuqala, izinto eziyisisekelo ezimbalwa okudingeka wazi:

    • I-JavaScript ingavaliwe kusiphequluli
    • I-JavaScript izosebenza njalo lapho ikhasi lilayishwa
    • I-JavaScript ithatha isikhathi ukulayisha ngokuxhumeka kwe-Intanethi
    • I-JavaScript isasuka kumakhasi e-cached
    • Ungabamba i-JavaScript ngaphakathi kwekhasi lewebhu noma ngaphandle kwefayela le-.js
    • I-JavaScript ihluke ngokuphelele kuneJava

    Kubalulekile futhi ukuqonda ukuthi iJavaScript empeleni izokuholela enhlekeleleni uma isetshenziswa ngendlela engafanele.

    Amakheli we-JavaScript akhiwe kahle futhi anobuhlakani azonciphisa iwebhusayithi yakho futhi alimaze ukuzulazula jikelele kwesayithi. Lokhu nakho kuthinta inani lokubuya kwezivakashi zakho (ngenxa yolwazi lomsebenzisi olubi) kanye namazinga ezinjini zokusesha (ngenxa yamanani wokuphendula wewebhusayithi aphambili kanye nokukhasa kwe-bot). Ukusiza ukuqinisekisa icala lami lapha, zifake ezicathulweni zokubuka. Uma iwebhusayithi oyivakashele ilayishe kancane, bekunzima ukuyisebenzisa, futhi, ukungavezi – ngabe ubuyela kusayithi? Ngeke.

    Ngezansi kunohlu oluncane lwezinto okufanele ucabange ngazo lapho ungeza iJavaScript kuyo iwebhusayithi yakho.

    • Ingabe i-JavaScript idinga ukuthi isayithi isebenze kahle?
    • Isayithi lizobonakala kanjani uma i-JavaScript ivinjelwe?
    • I-JavaScript izolimaza ukusebenza kweseva?
    • Ingabe uzongeza ukusiza kwe-JavaScript ukuhambisa isayithi lakho ngendlela ofuna ukuyifaka ngayo?

    Cha, angizami ukukusabisa ngala maphuzu.

    Eqinisweni, ungesabi Sebenzisa iJavaScript kuwebhusayithi yakho njengoba ihlinzeka ngezinzuzo zamathani futhi, njengoba kushiwo, isetshenziswa ezinkulu. Iphuzu eliyisihluthulelo engizama ukulifinyelela lapha akuyona nje ukuqhubeka unezela izici zeJavaScript kusayithi lapho kungenasidingo khona. Amanye amasayithi azodinga iJavaScript enkulu kunamanye; ezinye zidinga okuncane nje – Ukuthi isayithi eyodwa iyayenza akusho ukuthi nawe kufanele wenze okufanayo.

    I-Freebies: I-15 Cool I-JavaScript Imiklamo Yewebhusayithi Yakho

    Manje, ake sehle kulokho okufike lapha – ngezansi uhlu lwama-snippets e-15 JavaScript azothuthukisa isayithi lakho ngokusebenza noma ukubukeka. Ikhodi izophulwa ibe yizingxenye ezimbili, ikhanda nomzimba noma ifayela le- .js. Uma kunganikezwa isihloko sesigaba ngakho-ke asidingeki kuleso slathi esithile.

    I-1. Ukuqonda ividiyo ye-HTML5

    Isampula esheshayo

    umsebenzi uyaqonda_video () {Return! document.createElement („video”). canPlayType; // boolean} uma (! ukuqonda_video ()) {// Kufanele kube yisipheqululisidala noma i-IE. // Mhlawumbe yenza into efana nokufihla izilawuli // HTML5 Izilawuli. Noma yini … videoControls.style.display = ‘niciunul’; }

    Snippet Yenzani i-JavaScript?

    Le snippet encane izokuvimbela iwebhusayithi yakho ukuthi izame ukubonisa ividiyo isiphequluli esinakukwazi ukusekela, ukulondoloza amandla omgwaqo kanye nokucubungula amandla.

    I-2. Amakhukhi weJavaScript

    Isampula esheshayo

    / ** * Imisa ikhukhi ngegama elinikeziwe nenani. * * Igama Igama le-cookie * Inani le-cookie * [liphelelwa yisikhathi] Isikhathi sokuphelelwa kukhukhi (okuzenzakalelayo: ukuphela kweseshini yamanje) * [indlela] Indlela lapho ikhukhi isebenza khona (okuzenzakalelama) ((ezenzakalelayo: isizinda sedokhumenti yokushayela) * [evikelekile] Inani le-Boolean elibonisa uma ngabe ukuhanjiswa kukhukhi kudinga ukuhanjiswa okuphephile * / ukusebenza setCookie (igama, inani, ukuphelelwa isikhat) + "=" + ukuphunyuka (inani) + ((kuphelelwa isikhathi)? "; kuphelelwa isikhathi =" + expir.toGMTString (): "") + ((indlela)? "; indlela =" + indlela: "") + ((isizinda)? "; domeniu =" + domeniu: "") + ((kuvikelekile)? "; kuvikelekile": ""); } / ** * Ithola inani le-cookie echaziwe. * * Igama Igama le-cookie oyifunayo. * * Ibuyisa intambo equkethe inani lekhukhi echaziwe, * noma i-null uma ikhukhi lingekho. * / funcție GetCookie (igama) {var dc = document.cookie; prefix var = igama + "="; var qala = dc.indexOf (";" + isiqalo); uma (qala == -1) {qala = dc.indexOf (isiqalo); uma (qala! = 0) buyela null; } okunye {qala + = 2; } var end = document.cookie.indexOf (";", Qala); uma (ukuphela == -1) {end = dc.length; } cumpără ubuwena (dc.substring (qala + prefix.length, end)); } / ** * Unamathisela ikhukhi elibekiwe. * * Igama legama le-cookie * [indlela] yendlela yekhukhi (kumele ifane nendlela esetshenziselwa ukudala ikhukhi) * domeniu [domeniu] al cookie-ului (kumele ilingane nesizinda esisetshenziselwe ukudala ikhukhi) * / funcția DeleCookie (igama, indlela) (GetCookie (igama)) {document.cookie = igama + "=" + ((Indlela)? "; calea =" + indlela: "") + ((domeniu)? "; isizinda = "+ domeniu:" ") +"; expiră = Joi, 01 ianuarie-70 00: 00: 01 GMT "; }}

    Yenzani i-JavaScript fragment?

    Le snippet isikhashana kodwa iwusizo kakhulu, izovumela isayithi lakho ukuthi ligcine ulwazi kwikhompyutha yombukeli bese lifunda kwelinye iphuzu ngesikhathi. Le snippet ingasetshenziswa ngezindlela eziningi ezahlukene zokufeza imisebenzi ehlukile.

    I-3. Layisha kuqala izithombe zakho

    Isampula esheshayo

    izithombe ze-var = i-Array entsha (); i-preloadImages () {ye (i = 0; i

    Yenzani i-JavaScript fragment?

    Le snippet izovimbela isayithi lakho ukuthi lingabi nesikhathi esibucayi lapho ibonisa kuphela ingxenye yesayithi; Lokhu akukona nje kubukeka kubi kodwa futhi akusizi ngalutho. Konke okumele ukwenze wengeze izithombe zakho esigabeni sokulayisha kuqala futhi ulungele ukugoqa.

    I-4. Ukuqinisekiswa kwe-imeyili

    Isampula esheshayo

    Inhloko:

    umsebenzi uqinisekisaEmail (theForm) {if (/ ^ w + audiotaurwa-> /.test(theForm.email-id.value)) {cumpărați (iqiniso); } isexwayiso ("Ikheli le-imeyili elingavumelekile! Sicela ufake futhi ngokucophelela !."); buyela (ngamanga); }

    umzimba: Ikheli le-imeyili:

    Yenzani i-JavaScript fragment?

    Le-snippet izokuqinisekisa ukuthi ikheli le-imeyili elifomethwe kahle lifakwe kwifomu, alinakuqinisekisa ukuthi ikheli le-imeyili langempela, akukho ndlela yokukuhlola lokho ngeJavaScriptScript.

    I-5. Akukho Qhafaza kwesokudla

    Isampula esheshayo

    umsebenzi f1 () {uma (amaphepha.all) {buyela amanga; }} sebenza f2 (e) {if (document.layers || (document.getElementById) &! document.all)) {if (e.which == 2 || e.which == 3) {buyela amanga; }}} uma (document.layers) {imibhalo.captureEvents (Umcimbi.MOUSEDOWN); idokhumenti.onmousedown = f1; } okunye {document.onmouseup = f2; umqulu.oncontextmenu = f1; } idokhumenti.oncontextmenu = umsebenzi omusha ("buyisa amanga");

    Snippet Yenzani i-JavaScript?

    Le snippet izovimbela umbukeli ukuba akwazi ukuchofoza ngakwesokudla ekhasini lakho. Lokhu kunganciphisa umsebenzisi ojwayelekile ukuboleka izithombe noma ikhodi kusuka kusayithi lakho.

    I-6. Khombisa Izingcaphuno ezingekho emthethweni

    Isampula esheshayo

    Cap: bhalaRandomQuote = umsebenzi () {var quotes = Array entsha (); izingcaphuno [0] = "Isenzo yisilinganiso sangempela sobuhlakani."; izingcaphuno [1] = "I-baseball inenzuzo enkulu phezu kwekhilikithi yokuthi isheshe iphele."; izingcaphuno [2] = "Yonke inhloso, yonke isenzo, yonke imicabango, nakho konke ukuzwa, noma ngabe kukaziwa noma kungaziwa, ngumzamo wokukhulisa izinga lokuthula kwengqondo."; izingcaphuno [3] = "Inhloko enhle nenhliziyo enhle zihlala ziyinhlanganisela ebabazekayo."; var rand = Math.floor (Math.random () * izingcaphuno.length); umqulu.write (izingcaphuno [zamarandi]); } bhalaRandomQuote ();

    umzimba: bhalaRandomQuote ();

    Yenzani i-JavaScript fragment?

    Kulungile lokhu akusiyo ishidi ukuthi zonke izingosi zingasebenzisa kodwa zingasetshenziswa ukubonisa okungaphezulu nje kokucaphuna okungahleliwe. Ungashintsha okuqukethwe ok izingcaphuno kunoma yini oyifunayo futhi ube nezithombe ezingahleliwe noma umbhalo oboniswe noma kuphi kusayithi lakho.

    I-7. Izixhumanisi Zangaphambilini / Ezilandelayo

    Isampula esheshayo

    Ikhasi langaphambilini | Ikhasi elilandelayo

    Snippet Yenzani i-JavaScript?

    Le snippet inkulu uma unamakhasi amaningi ku-athikili noma kusifundo. Izovumela umsebenzisi ukuthi upheqa phakathi kwamakhasi kalula. Kuyinto encane futhi isisindo esincane esivela endaweni yokubuka.

    I-8. Beka i-bookmark Ekhasini

    Isampula esheshayo

    Snippet Yenzani i-JavaScript?

    Le snippet izovumela umsebenzisi ukuthi azimise ikhasi lakho kalula; konke okumele bakwenze ukuchofoza isixhumanisi. Izici zayo ezincane ezifana nalokhu ezingandisa ababukeli bakho ulwazi jikelele.

    I-9. Isixhumanisi Esilula Sekhasi Lephepha

    Isampula esheshayo

    Ikhasi Lokuphrinta

    Snippet Yenzani i-JavaScript?

    Lesi sixhumanisi esincane sizovumela imibono yakho ukuba iphrinta kalula ikhasi lakho. Isebenzisa isici sokuphrinta esheshayo sesivele sisethiwe ngesiphequluli sakho futhi asisebenzisi izinsiza kuze kuchofozwe.

    I-10. Khombisa usuku oluhleliwe

    Isampula esheshayo

    Cap: show showDate () {var d = usuku olusha (); var curr_date = d.getDate (); var curr_month = d.getMonth () + 1; // izinyanga zero-zero curr_year = d.getFullYear (); umqulu.write (curr_date + "-" + curr_month + "-" + curr_year); }

    umzimba: showDate ();

    Snippet Yenzani i-JavaScript?

    Le snippet izokuvumela ukuba ubonise usuku lwamanje noma kuphi ekhasini lakho lewebhu futhi akudingeki libuyekezwe. Mane nje uyibeke endaweni futhi ukhohlwe ngakho.

    I-11. Isihlukanisi seComma

    Isampula esheshayo

    Cap: i-function addCommas (inombolo) {num + = ”; var n1 = inombolo.split (‘.’); var n2 = n1 [0]; var n3 = n1.lungime> 1? ” + n1 [1]: ”; var temp = / (d +) (d {3}) /; ngenkathi (temp.test (n2)) {n2 = n2.replace (temp, ” + ‘,’ + ”); } var out = Returnare n2 + n3; umqulu.bhala (ngaphandle); }

    umzimba: i-addCommas ("4550989023");

    Snippet Yenzani i-JavaScript?

    Le snippet ingasetshenziswa ikakhulukazi amasayithi asebenzisa izinombolo kaningi. Le snippet izogcina izinombolo zakho zibukeka ezifanayo ebhodini. Konke okumele ukwenze ukukopisha umugqa womzimba lapho ufuna ukwengeza khona inombolo bese ushintsha inombolo lapho ngenombolo yakho.

    I-12. Thola Indawo Yokubonisa Yesiphequluli

    Isampula esheshayo

    Ububanzi besikhathi sakho sokubuka ngu ‘+ viewportwidth +’ x ‘+ viewportheight +’

    „); // ->

    Snippet Yenzani i-JavaScript?

    Le snippet izokuvumela ukuthi uthole ububanzi nokuphakama kwendawo yokubonisa kusiphequluli sakho sokubukwa. Lokhu kuzonikeza umklami ikhono lokudala nokusebenzisa izibonisi caracterhlukene ngokususelwa kusayizi wesiphequluli sesiphequluli somsebenzisi.

    I-13. Phinda uqondise kabusha ngokubambezeleka kokukhetha

    Isampula esheshayo

    setTimeout ("windows.location.href = ‘http://walkerwines.com.au/’", 5 * 1000);

    Snippet Yenzani i-JavaScript?

    Le snippet izokuvumela ukuba uqondise kabusha ababukeli bakho kwenye ikhasi futhi unendlela yokubeka ukulibaziseka. Ukusetshenziswa kwalesi snippet kuyinto enhle ozichaza futhi kuyithuluzi eliwusizo kakhulu ukuba babe ebhande lakho.

    I-14. Thola ama-iPhones

    Probă

    uma ((navigator.userAgent.match (/ iPhone / i)) || (navigator.userAgent.match (/ iPod / i)) {if (document.cookie.indexOf ( "iphone_redirect = amanga") == -1) {windows.location = "http://m.espn.go.com/wireless/?iphone&i = COMR"; }}

    Snippet Yenzani i-JavaScript?

    Le snippet izokuvumela ukuba ubone ukuthi umbukeli wakho use-iPhone noma i-iPod evumela ukuthi ubonise okuqukethwe okuhlukile kubo. Lo mdlalo uzuzisa kakhulu kangakanani ukuthi imakethe yeselula ikhulu kangakanani futhi utilizareqhubeka ukhula.

    I-15. Phrinta Umlayezo ku-Isimo Bar

    Isampula esheshayo

    “; // ->

    Snippet Yenzani i-JavaScript?

    Le snippet encane izokuvumela ukuthi uphrinte umlayezo kubha yomumo. Ungabonisa izindaba zakamuva noma ezibalulekile endaweni ezobamba iso lomsebenzisi.

    Jeffrey Wilson Administrator
    Sorry! The Author has not filled his profile.
    follow me
      Like this post? Please share to your friends:
      Adblock
      detector
      map