Uyisebenzisa nini iNgxelo kwiNkqubo ye-HTML ngeJavaScript

NguJohn Paul Mueller

Ngokwenyani awungekhe ubaleke usebenzisa iukubaingxelo ngeJavaScript. Inkqubo ye-ukubaIsiteyitimenti siqhele ukuvavanywa ukuba ngaba kukho into eyenzekileyo okanye hayi, nokuba idatha ikuluhlu okanye akunjalo, nokuba umsebenzisi ufuna ukwenza umsebenzi othile.

Uyenza njani elula ukuba ingxelo kwiJavaScript

Enye yezona zinto ziqhelekileyo ezisetyenziswayoukubaingxelo kukwenza ukhetho olulula. Xa umsebenzisi ethatha inyathelo elithile, kwenzeka into ethile. Kumzekelo olandelayo, xa umsebenzisi ecofa u-Kulungile kwibhokisi yencoko yababini, usetyenziso lubonisa umyalezo oyimfihlo.

Ishelf life yeziyobisi
// Create an expression that results in true or false. var Answer = confirm( 'Do you want to display the secret message?'); // Test the expression using the if statement. if (Answer) { // Display the secret message when the user // clicks OK. document.getElementById('Result').innerHTML = 'This is the secret message!'; }

Kule meko,Phendulainokuqulatha kuphelayinyaniokanyeUbuxokikubaqinisekisa ()ayivelisi nawaphi na amanye amaxabiso. Ngenxa yoko, awudingi ukwenza naluphi na uhlobo lwexabiso lokukhangelaPhendulaKonke okufuneka ukwenze kukumisela ixabiso lenyanisoPhendulaukwenza isigqibo.

Zonke izigqibo ezenziwayo onokuzenza ziya kuba nexabiso lenyaniso lohlobo oluthile-nokuba yinyani okanye bubuxoki. Ngamanye amaxesha ixabiso lenyaniso lifihliwe, njengaxa usebenza ngesakhiwo sokutshintsha, kodwa ixabiso lenyaniso likho.

uguquko kwi-toradol

Iikhompyuter aziqondi nantoni na eyenye ngaphandle kwenyani okanye ubuxoki. Kukho iindlela ezenza ukuba kubonakale ngathi ikhompyuter inokwenza enye into, kodwa enyanisweni, konke kuyehla ekuthatheni isigqibo esinyani okanye esingeyonyani njengoko kubonisiwe apha.

Yintoni enye ongayenza nge ingxelo?

Usebenzisa iukubaingxelo kwiimeko xa isicelo sifuna ukwenza into xa umsebenzisi ephendula ngokuchanekileyo, kodwa ungalihoyi igalelo xa impendulo ingachanekanga. Nangona kunjalo, kukho amaxesha apho kufuneka wenze into xa igalelo lichanekile kwaye enye into xa ingalunganga. Kule meko, uyongezaenye intoIgatya ukuyaukubaingxelo njengoko kubonisiwe kulo mzekelo ulandelayo.

// Create an expression that results in true or false. var Answer = confirm( 'Do you want to display the secret message?'); // Test the expression using the if statement. if (Answer) { // Display the secret message when the user // clicks OK. document.getElementById('Result').innerHTML = 'This is the secret message!'; } else { // Perform an alternative task. alert('Click OK next time to see the message!'); }

UKUYA Igatya lulwandiso lwesakhiwo. Kule meko, ienye intoIgatya landisaukubastructure ukubandakanya ikhowudi yesibini ephatha imeko engeyonyani. Umzekelo usakhupha umyalezo oyimfihlo xa umsebenzisi ecofa u-OK kwifayile ye-qinisekisa ()ibhokisi yencoko.

Nangona kunjalo, ngoku ikhowudi ikwabonisa ifayile ye-isilumkiso ()incoko yababini xa umsebenzisi ecofa ukuRhoxisa. Eli nyathelo lesibini linceda umsebenzisi aqonde indlela yokuphendula kwifayile ye-qinisekisa ()ibhokisi yencoko yababini yokufumana imveliso eyahlukileyo.

Yintoni elungileyo yecyclobenzaprine

Uyenza njani indlwana ukuba iinkcazo kwiJavaScript

Zininzi izizathu zokuba kutheni indlwane ukubaiingxelo-Oko kukuthi, beka enyeukubaingxelo ngaphakathi komnye. Kule meko, umsebenzisi ukhetha ukhetho kwiscreen,Khangela uKhetho ()wenza itshekhi yolo khetho, emva kokoKhangela uKhetho ()bonisa iziphumo ezichanekileyo kwiscreen.

function CheckChoice(option) { // Verify that the input is a number. if (typeof(option) != 'number') { // Display an error dialog. alert('Please provide numeric input!'); // Return without doing anything more. return; } // Ensure that option is actually an integer. var Select = Math.round(option); // Verify that the input is in range. if ((Select 3)) { // Display an error dialog. alert('The value supplied is out of range!'); // Return without doing anything more. return; } // Make a selection. if (Select == 1) { document.getElementById('Result').innerHTML = 'You chose Item A.'; } else { if (Select == 2) { document.getElementById('Result').innerHTML = 'You chose Item B.'; } else { document.getElementById('Result').innerHTML = 'You chose Item C.'; } } }

Lo mzekelo awuthembeli kumthombo owaziwayo wokufaka, ke uqala ngokwenza uhlolo olwahlukileyo lwedatha. Itsheki yokuqala iqinisekisa ukuba lowo ufowunayo unikezele ngexabiso lamanani. Emva kwayo yonke loo nto, umntu ofowunayo unokubonelela ngentambo okanye ngexabiso leBoolean endaweni yoko. Ngalo nto, igalelo linokuba sisikhombisi komnye umsebenzi okanye nayiphi na into exhaswa yiJavaScript-awazi nje.

Inyathelo elilandelayo liguqula ukufakwa kwamanani kwinani elipheleleyo. Uguquko lwedatha lubalulekile kwiJavaScript kuba iphatha amanani apheleleyo kunye namaxabiso encopho yokudada njengamanani. Ukuba ufuna ixabiso elipheleleyo, usebenzisaIMathematika ()ukuyifumana yeyona ndlela ifanelekileyo yokuhamba. Lo msebenzi urhangqa igalelo kwixabiso elikufutshane elipheleleyo, okuthetha ukuba awupheli uzama ukuthelekisa ngokuchasene namaxabiso anje nge3.5.

Okwangoku, uyazi ukuba unenombolo kwaye inani lilinani elipheleleyo, kodwa awazi nokuba inani likuluhlu oluchanekileyo na. Ukusilela kuluhlu lokujonga amaxabiso egalelo kungunobangela woyee omkhulu kwizicelo zeJavaScript.Khangela uKhetho ()ilindele amaxabiso apheleleyo kwinani eli-1 ukuya kwele-3, ke uluhlu lokujonga lujonga la maxabiso.

IndlwaneukubaIsiteyitimenti siphantse sibe yinto engekhoyo okwangoku. Uyakwazi okoKhethaiqulethe1,Mbini, okanye3. Eyokuqalaukubaingxelo ijonga ixabiso loku-1 kwaye ibonisa umyalezo xa ifumana elo xabiso. Xa ixabiso liyenye into ngaphandle kwe-1, ienye intoIgatya lithatha indawo. Ngaphakathienye intoIgatya yindawo yokuhlalaukubaingxelo.

Okuukubaukukhangela ingxeloKhethangexabiso leMbinikwaye ibonisa umyalezo ofanelekileyo xa kunjalo. NiniKhethangu3,enye intoIgatya lale yesibini, lenziwe,ukubaingxelo ibonisa umyalezo ofanelekileyo.

bentyl yeyantoni

umfanekiso0.jpg