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
* Transfer the existing translation, ready for review
Co-authored-by: maoxiaoke <thebigyellowbee@qq.com>
resolvejavascript-tutorial#2
* fix(hello-world): Adjust some contents
* translate more contents
* 👌 fix: Adjust some words due to code review changes
Signed-off-by: sqrtthree <imsqrtthree@gmail.com>
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Show an alert with an external script
5
+
# 使用外部的脚本显示一个提示语
6
6
7
-
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.
The tutorial that you're reading is about core JavaScript, which is platform-independent. Further on, you will learn Node.JS and other platforms that use it.
But, we need a working environment to run our scripts, and, just because 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. On the other hand, browser details are explained in detail in the [next part](/ui) of the tutorial.
So first, let's see how to attach a script to a webpage. For server-side environments, you can just execute it with a command like `"node my.js"`for Node.JS.
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type`by default. No attribute is required.
50
+
: 在老的 HTML4 标准中,`<script>` 标签有 type 属性。通常是 `type="text/javascript"` 。 现在的 HTML 标准已经默认存在该 `type`属性。该属性不是必须的。
51
51
52
-
The `language`attribute: <code><script <u>language</u>=...></code>
53
-
: This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.
: In really ancient books and guides, one may find comments inside `<script>`, like this:
55
+
脚本前后的注释。
56
+
: 在非常古老的书籍和指南中, 可能会在 `<script>` 标签里面找到注释,就像这样:
57
57
58
58
```html no-beautify
59
59
<script type="text/javascript"><!--
60
60
...
61
61
//--></script>
62
62
```
63
63
64
-
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
If we have a lot of JavaScript code, we can put it into a separate file.
69
+
如果你有大量的 JavaScript 代码,我们可以将它放入一个单独的文件。
70
70
71
-
The script file is attached to HTML with the `src`attribute:
71
+
脚本文件可以通过 `src`属性添加到 HTML 文件中。
72
72
73
73
```html
74
74
<scriptsrc="/path/to/script.js"></script>
75
75
```
76
76
77
-
Here `/path/to/script.js`is an absolute path to the file with the script (from the site root).
77
+
这里 ,`/path/to/script.js`是脚本文件的绝对路径(从站点根目录开始)。
78
78
79
-
It is also possible to provide a path relative to the current page. For instance, `src="script.js"`would mean a file `"script.js"`in the current folder.
There is much more to learn about browser scripts and their interaction with the web-page. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves from it. We'll be using a browser as a way to run JavaScript, which is very convenient for online reading, but yet one of many.
0 commit comments