You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Take the solution of the previous task <info:task/hello-alert>. Modify it by extracting the script content into an external file `alert.js`, residing in the same folder.
7
+
Вземете решението от предходната задача <info:task/hello-alert>. Модифицирайте го, като извлечете скрипта от съдържанието и го поставите в отделен, външен файл `alert.js`, намиращ се в същата директория.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/01-hello-world/article.md
+44-40Lines changed: 44 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -1,87 +1,89 @@
1
1
# Hello, world!
2
2
3
-
This part of the tutorial is about core JavaScript, the language itself.
3
+
В тази част от урока ще разглеждаме езика JavaScript в неговия чист вид.
4
4
5
-
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like`alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui)of the tutorial.
5
+
За целта ще ни е необходима среда, в която да изпълняваме нашите скриптове, тъй като това е онлайн книга, браузъра е добър избор като среда. Ще се стремим да използваме минимално количество браузър-специфични команди (като`alert`), за да не губите време, ако сте планувате да се занимавате с разработка в друга среда (като Node.js). Ще се фокусираме върху разработката на JavaScript за браузър в [друга част](/ui)от уроците.
6
6
7
-
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like`"node my.js"`.
7
+
Първо нека видим как можем да закачим скрипт към уеб страница. За разработка в сървърна среда (като Node.js), може да изпълни скрипта с командата`"node my.js"`.
8
8
9
9
10
-
## The "script" tag
10
+
## "script" таг
11
11
12
-
JavaScript programs can be inserted into any part of an HTML document with the help of the `<script>`tag.
12
+
JavaScript програми могат да бъдат поставяни в всяка част от HTML документ, с помощта на `<script>`таг.
13
13
14
-
For instance:
14
+
Пример:
15
15
16
16
```html run height=100
17
17
<!DOCTYPE HTML>
18
18
<html>
19
19
20
20
<body>
21
21
22
-
<p>Before the script...</p>
22
+
<p>Преди script...</p>
23
23
24
24
*!*
25
25
<script>
26
26
alert( 'Hello, world!' );
27
27
</script>
28
28
*/!*
29
29
30
-
<p>...After the script.</p>
30
+
<p>... След script.</p>
31
31
32
32
</body>
33
33
34
34
</html>
35
35
```
36
36
37
37
```online
38
-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
38
+
Можете да изпълните този примерен код като натиснете бутона "Play" (пусни) в горният десен ъгъл, на горната кутия.
39
39
```
40
40
41
-
The `<script>`tag contains JavaScript code which is automatically executed when the browser processes the tag.
41
+
`<script>`тагът съдържа JavaSript код, който ще се изпълни автоматично, при обработка на тага от браузъра.
42
42
43
43
44
-
## Modern markup
44
+
## Модерно оформление
45
45
46
-
The `<script>`tag has a few attributes that are rarely used nowadays but can still be found in old code:
46
+
`<script>`таговете имат няколко вече рядко използвани атрибути, които все още могат да бъдат намерени в стар код.
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic; we'll talk about modules in another part of the tutorial.
: Според старият HTML стандарт, HTML4, `script` тагът се е изисквало да съдържа атрибут `type`. Като обикновено е бил `type="text/javascript"`. Този атрибут вече не е задължителен. Ноивят HTML стандарт тотално изменя значението на този атрибут, сега този атрибут може да се използва за JavaScript модули, но това е тема за по-напреднали, която ще разгледаме в следващ урок.
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
: Този атрибут е бил използван да обозначава езикът на скрипта. Той вече е загубил значението си, тъй като JavaScript e езикa по подразбиране.
53
53
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
54
+
55
+
Коментари преди и след скриптове
56
+
: В някои наистина дрвени книги и уроци, може да намерите коментари в `<script>` тагове, като тези:
56
57
57
58
```html no-beautify
58
59
<script type="text/javascript"><!--
59
60
...
60
61
//--></script>
61
62
```
62
63
63
-
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
64
+
65
+
Този трик не се използва в модерния JavaScript. Тези коментраи могат да скрият JavaScript код от стари браузъри, които не могат да обработват `<script>` тагове. Тъй като браузърите, дистрибутирани през последните 15 години, нямат този проблем, този вид коментари могат да помогнат за индетифициране на наистина стари браузъри.
64
66
65
67
66
-
## External scripts
68
+
## Външни скриптове
67
69
68
-
If we have a lot of JavaScript code, we can put it into a separate file.
70
+
Ако имаме много JavaScript код, може да го отделим в различн файл.
69
71
70
-
Script files are attached to HTML with the`src`attribute:
72
+
Скрипт файловете се закачат към HTML файловете посредством`src`атрибута:
71
73
72
74
```html
73
75
<scriptsrc="/path/to/script.js"></script>
74
76
```
75
77
76
-
Here,`/path/to/script.js`is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"` would mean a file `"script.js"`in the current folder.
78
+
Тук`/path/to/script.js`е абсолютният път до скрипта започващ от нивото от което се зарежда и сайта в файловата система. Също така може да се използва и релативен път, от текущата страница, пример за това е `src="script.js"`, което означава че ще бъде достъпен файла `"script.js"`от текущата директория.
77
79
78
-
We can give a full URL as well. For instance:
80
+
Може да предоставим и пълен URL адрес. Пример за това е:
За да закачим няколко скрипта, трабва да използваме и няколко тага:
85
87
86
88
```html
87
89
<scriptsrc="/js/script1.js"></script>
@@ -90,29 +92,30 @@ To attach several scripts, use multiple tags:
90
92
```
91
93
92
94
```smart
93
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
95
+
Като правило е прието, че само най-простите скриптове, се поставят в HTML файловете, като по сложните се поставят в отделни файлове.
94
96
95
-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
97
+
Ползата от отделянето на файлове е, че браузъра ще свали този файл и ще го съхрани в своя [кеш](https://bg.wikipedia.org/wiki/%D0%9A%D0%B5%D1%88-%D0%BF%D0%B0%D0%BC%D0%B5%D1%82)
96
98
97
-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
99
+
Други страници, които реферират същият скрипт, ще могат да го заредят от кеша вместо да правят нова заявка, което означава че файла ще бъде изтеглен само веднъж.
98
100
99
-
That reduces traffic and makes pages faster.
101
+
Това намалява трафикът и прави страниците по-бързи.
100
102
```
101
103
102
-
````warn header="If `src`is set, the script content is ignored."
103
-
A single `<script>`tag can't have both the `src` attribute and code inside.
104
+
````warn header="Ако на`src`атрибута е зададена стойност, то тогава съдържанието на скрипта бива игнорирано."
105
+
Един `<script>`таг може да съдържа в себе си едноверемено код и `src` атрибут.
104
106
105
-
This won't work:
107
+
108
+
Това няма да проработи:
106
109
107
110
```html
108
111
<script*!*src*/!*="file.js">
109
-
alert(1); //the content is ignored, because src is set
112
+
alert(1); //съдържанието е игнорирано, тъй като има задеден src атрибут
110
113
</script>
111
114
```
112
115
113
-
We must choose either an external`<script src="…">`or a regular`<script>`with code.
116
+
Ние трябва да изберем или външен`<script src="…">`таг или обикновен`<script>`таг с код.
114
117
115
-
The example above can be split into two scripts to work:
118
+
Горният пример може да бъде разделен на два скрипта за да проработи:
116
119
117
120
```html
118
121
<scriptsrc="file.js"></script>
@@ -122,11 +125,12 @@ The example above can be split into two scripts to work:
122
125
```
123
126
````
124
127
125
-
## Summary
128
+
## Обобщение
129
+
130
+
- Може да използваме `<script>` таг за да добавяме JavaScript код към страница.
131
+
- Атрибутите `type` и `language` не са задължиетлни.
132
+
- Скрипт от външен за страницата файл, може да бъде закачан посредством `<script src="path/to/script.js"></script>`.
126
133
127
-
- We can use a `<script>` tag to add JavaScript code to a page.
128
-
- The `type` and `language` attributes are not required.
129
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
130
134
135
+
Има още много, което може да се научи за скриптовете изпълнявани в браузъра и техите интеракции с уеб страниците, но нека незабравяме че тази част от урока е посветена на езика JavaScript, за това не трябва да се разсейваме, с браузър-специфични имплементации. Ние ще използваме браузъра, като средство да изпълняваме JavaScript код, което е много удобно, за това онлайн четиво.
131
136
132
-
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
0 commit comments