Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3
Interaction: alert, prompt, confirm#72
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
7 commits Select commitHold shift + click to select a range
2bfd18a
1.2.6
otmon76af872ba
Update 1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md
otmon768434f7d
Update 1-js/02-first-steps/06-alert-prompt-confirm/article.md
otmon76d50ea26
Update 1-js/02-first-steps/06-alert-prompt-confirm/article.md
otmon760d62da6
Update 1-js/02-first-steps/06-alert-prompt-confirm/article.md
otmon76b69d7ea
Update 1-js/02-first-steps/06-alert-prompt-confirm/article.md
otmon763c3dd2a
Update 1-js/02-first-steps/06-alert-prompt-confirm/article.md
otmon76File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
12 changes: 6 additions & 6 deletions1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions1-js/02-first-steps/06-alert-prompt-confirm/1-simple-page/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2,8 +2,8 @@ importance: 4 | ||
--- | ||
#Jednoduchá stránka | ||
Vytvořte webovou stránku, která se zeptá na jméno a pak ho zobrazí. | ||
[demo] |
82 changes: 41 additions & 41 deletions1-js/02-first-steps/06-alert-prompt-confirm/article.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,105 @@ | ||
#Interakce: alert, prompt, confirm | ||
Protože jako demonstrační prostředí budeme používat prohlížeč, podíváme se na několik funkcí sloužících k interakci s uživatelem: `alert`, `prompt`a `confirm`. | ||
## alert | ||
Tuto funkci jsme už viděli. Zobrazí zprávu apočká, až uživatel stiskne tlačítko „OK“. | ||
Příklad: | ||
```js run | ||
alert("Ahoj"); | ||
``` | ||
Miniokno se zprávou se nazývá *modální okno*.Slovo „modální“ znamená, že uživatel nemůže komunikovat se zbytkem stránky, mačkat jiná tlačítka apod., dokud nevyhodnotí toto okno--v tomto případě dokud nestiskne „OK“. | ||
## prompt | ||
Funkce`prompt`přijímá dva argumenty: | ||
```js no-beautify | ||
výsledek = prompt(titulek, [default]); | ||
``` | ||
Zobrazí modální okno s textovou zprávou, vstupní pole pro návštěvníka a tlačítka OK a Storno. | ||
`titulek` | ||
:Text, který se má zobrazit návštěvníkovi. | ||
`default` | ||
:Volitelný druhý parametr, úvodní hodnota ve vstupním poli. | ||
```smart header="Hranaté závorky v syntaxi `[...]`" | ||
Hranaté závorky okolo`default`ve výše uvedené syntaxi označují, že parametr je dobrovolný a není vyžadován. | ||
``` | ||
Návštěvník může do vstupního pole něco napsat a stisknoutOK.Pak získáme napsanýtextjako `výsledek`.Nebo může zrušit vstup stisknutím tlačítka Storno nebo klávesy`key:Esc`. Pak jako `výsledek` obdržíme `null`. | ||
Volání`prompt`vrátítextze vstupního pole nebo`null`, pokud byl vstup zrušen. | ||
Příklad: | ||
```js run | ||
letvěk = prompt('Kolik je ti let?', 100); | ||
alert(`Je ti ${věk} let!`); //Je ti 100let! | ||
``` | ||
````warn header="Pro IE vždy uvádějte `default`" | ||
Druhý parametr je nepovinný, ale jestliže ho neuvedeme, Internet Explorervloží do dotazu text `"undefined"`. | ||
Spusťte si vInternetExploreru tento kód a uvidíte: | ||
```js run | ||
let test = prompt("Test"); | ||
``` | ||
Aby dotazy vypadaly dobře i vIE,doporučujeme vždy uvádět i druhý argument: | ||
```js run | ||
let test = prompt("Test", ''); // <--pro IE | ||
``` | ||
```` | ||
## confirm | ||
Syntaxe: | ||
```js | ||
výsledek = confirm(otázka); | ||
``` | ||
Funkce`confirm`zobrazí modální okno s otázkou -- v našem případě obsaženou v promenné `otázka` -- a dvěma tlačítky: OKa Storno. | ||
Výsledek bude`true`, jestliže uživatel stiskne OK, jinak bude`false`. | ||
Příklad: | ||
```js run | ||
letjeŠéf = confirm("Jsi šéf?"); | ||
alert(jeŠéf ); //pokud bylo stisknuto OK, tak true | ||
``` | ||
##Shrnutí | ||
Uvedli jsme tři funkce specifické pro prohlížeče, které umožňují interakci s návštěvníky: | ||
`alert` | ||
:Zobrazí zprávu. | ||
`prompt` | ||
:Zobrazí zprávu, která požádá uživatele o zadání textu. Vrátí zadanýtextnebo `null`, pokud uživatel stiskl tlačítko Storno nebo klávesu `key:Esc`. | ||
`confirm` | ||
:Zobrazí zprávu a počká, než uživatel stiskne „OK“ nebo „Storno“. Vrátí`true`, pokud stiskl OK, nebo `false`, pokud stiskl Storno nebo klávesu`key:Esc`. | ||
Všechny tyto metody jsou modální: pozastaví vykonávání skriptu a neumožní návštěvníkovi komunikovat se zbytkem stránky, dokud okno nezmizí. | ||
Všechny uvedené metody mají dvě omezení: | ||
1.Poloha modálního okna je stanovena prohlížečem. Obvykle je uprostřed. | ||
2.Vzhled okna závisí na prohlížeči. Nelze jej upravit. | ||
To je cena za jednoduchost. Existují jiné způsoby, kde můžete upravit vzhled oken a umožnit bohatší interakci s návštěvníkem, ale pokud nám na těchto věcech příliš nezáleží, tyto metody fungují dobře. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.