Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Translated article about alert, prompt and confirm#73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
meilune merged 3 commits intojavascript-tutorial:masterfrommeilune:master
Jul 25, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
JavaScript-code:
JavaScript-kodas:

```js demo run
let name = prompt("What is your name?", "");
let name = prompt("Koks jūsų vardas?", "");
alert(name);
```

The full page:
Pilnas puslapis:

```html
<!DOCTYPE html>
Expand All@@ -15,7 +15,7 @@ The full page:
<script>
'use strict';

let name = prompt("What is your name?", "");
let name = prompt("Koks jūsų vardas?", "");
alert(name);
</script>

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2,8 +2,8 @@ importance: 4

---

#A simple page
#Paprastas puslapis

Create a web-page that asks for a name and outputs it.
Sukurkite internetinį puslapį, kuris klausia vardo ir paskui jį parodo.

[demo]
78 changes: 39 additions & 39 deletions1-js/02-first-steps/09-alert-prompt-confirm/article.md
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,109 +1,109 @@
#Interaction: alert, prompt, confirm
#Interakcija: alert, prompt, confirm

In this part of the tutorial we cover JavaScript language "as is", without environment-specific tweaks.
Šioje pamokų dalyje kalbėsime apie JavaScript kalbą "tokia kokia ji yra", be aplinkai būdingų pataisymų.

But we'll still be using the browser as our demo environment, so we should know at least a few of itsuser-interface functions. In this chapter, we'll get familiar with the browser functions`alert`, `prompt`and `confirm`.
Bet vis dar naudosime naršykles kaip mūsų pavyzdinę aplinką, tad turėtume žinoti bent kelias vartotojo sąsajos (ang.user-interface) savybes. Šiame skyriuje susipažinsime su šiomis naršyklės funkcijomis`alert`, `prompt`ir `confirm`.

## alert

Syntax:
Sintaksė:

```js
alert(message);
```

This shows a message and pauses script execution until the user presses "OK".
Parodo žinutę ir sustabdo skriptą iki kol vartotojas paspaus "OK".

For example:
Pavyzdžiui:

```js run
alert("Hello");
alert("Labas");
```

The mini-window with the message is called a*modal window*. The word "modal" means that the visitor can't interact with the rest of the page, press other buttons, etc. until they have dealt with the window. In this case--until they press "OK".
Miniatiūrinis langelis su žinute yra vadinamas *modaliniu langeliu* (ang.*modal window*). Žodis "modalinis" reiškia, kad lankytojas negali naudotis likusiu puslapiu, spausti kitų mygtukų ir t.t. kol nesusitvarkė su langeliu. Šiuo atveju--iki kol paspaus "OK".

## prompt

The function`prompt`accepts two arguments:
Funkcija`prompt`priima du argumentus:

```js no-beautify
result = prompt(title, [default]);
```

It shows a modal window with a text message, an input field for the visitor, and the buttons OK/Cancel.
Parodo modalinį langelį su paprasta tekstine žinute, įvesties laukeliu lankytojui ir mygtukus OK/Cancel.

`title`
:The text to show the visitor.
:Tekstas, kurį reikės parodyti lankytojui.

`default`
:An optional second parameter, the initial value for the input field.
:Nebūtinas antras parametras, pradinė vertė įvesties laukeliui.

The visitor may type something in the prompt input field and pressOK.Or they can cancel the input by pressingCancelor hitting the`key:Esc`key.
Lankytojas gali ką nors įvesti laukelyje ir paspaustiOK.Arba jie gali atšaukti paspausdamiCancelar klaviatūroje`key:Esc`mygtuką.

The call to`prompt`returns the text from the input field or`null` if the input was canceled.
Iššauktas`prompt`grąžina tekstą iš įvesties laukelio arba`null`, jeigu įvestis buvo atšaukta.

For instance:
Pavyzdžiui:

```js run
let age = prompt('How old are you?', 100);
let age = prompt('Kiek jums metų?', 100);

alert(`You are ${age}years old!`); //You are 100years old!
alert(`Jums yra ${age}metų!`); //Jums yra 100metų!
```

````warn header="In IE: always supply a `default`"
The second parameter is optional, but if we don't supply it, Internet Explorerwill insert the text`"undefined"`into theprompt.
````warn header="IE naršyklėje: visada nurodykite `default`"
Antras parametras nėra būtinas, bet jeigu jo nepateiksite, Internet Explorerįtrauks`"undefined"`įprompt tekstą.

Run this code inInternet Explorerto see:
Norėdami išbandyti, paleiskite šį kodąInternet Explorernaršyklėje:

```js run
let test = prompt("Test");
let test = prompt("Testas");
```

So, for prompts to look good inIE,we recommend always providing the second argument:
Tad tam, kad prompt visada gerai atrodytųIE,mes rekomenduojame visada pateikti antrą argumentą:

```js run
let test = prompt("Test", ''); // <--for IE
let test = prompt("Testas", ''); // <--skirta IE
```
````

## confirm

The syntax:
Sintaksė:

```js
result = confirm(question);
```

The function`confirm`shows a modal window with a`question`and two buttons: OKand Cancel.
Funkcija`confirm`parodo modalinį langelį su`question`(klausimu) ir dviem mygtukais: OKir Cancel.

The result is`true` ifOKis pressed and`false`otherwise.
Rezultatas būna`true`, jeigu paspaudžiamasOKir`false`kitu atveju.

For example:
Pavyzdžiui:

```js run
let isBoss = confirm("Are you the boss?");
let isBoss = confirm("Ar tu esi bosas?");

alert( isBoss ); // true if OK is pressed
alert( isBoss ); // true, jeigu paspaudžiamas OK
```

##Summary
##Santrauka

We covered 3browser-specific functions to interact with visitors:
Mes aptarėme 3naršyklei būdingas funkcijas skirtas bendrauti su lankytojais:

`alert`
:shows a message.
:parodo žinutę.

`prompt`
:shows a message asking the user to input text. It returns the text or, ifCancelbutton or`key:Esc`is clicked, `null`.
:parodo žinutę prašydamas vartotojo įvesti tekstą. Grąžina tekstą arba, jeigu paspaudžiamasCancelar`key:Esc`grąžinamas `null`.

`confirm`
:shows a message and waits for the user to press"OK"or "Cancel".It returns`true`for OKand `false`for Cancel/`key:Esc`.
:parodo žinutę ir laukia kol lankytojas paspaus"OK"arba "Cancel".Grąžina`true`kai OKir `false`kai Cancel/`key:Esc`.

All these methods are modal: they pause script execution and don't allow the visitor to interact with the rest of the page until the window has been dismissed.
Visi šie veiksmai yra modaliniai: jie sustabdo skripto vykdymą ir neleidžia lankytojams naudotis likusiu puslapiu kol langelis nėra uždaromas.

There are two limitations shared by all the methods above:
Visus anksčiau minėtus metodus sieja du apribojimai:

1.The exact location of the modal window is determined by the browser. Usually, it's in the center.
2.The exact look of the window also depends on the browser. We can't modify it.
1.Naršyklė nustato tikslią modalinio langelio vietą. Dažniausiai tai yra centras.
2.Tiksli langelio išvaizda taip pat priklauso nuo naršyklės. Mes jo pakeisti negalime.

That is the price for simplicity. There are other ways to show nicer windows and richer interaction with the visitor, but if "bells and whistles" do not matter much, these methods work just fine.
Tokia yra paprastumo kaina. Yra daug kitų būdų parodyti gražesnius langelius ir naudoti puikesnį bendravimą su lankytojais, bet jeigu nėra labai svarbu įmantrumai esami metodai veikia kuo puikiausiai.

[8]ページ先頭

©2009-2025 Movatter.jp