您的位置:首页 > Web前端 > JavaScript

JavaScript在网页中的位置

2015-06-28 11:04 561 查看
JavaScript is inserted into HTML pages by using the <script> element. This element can be used

to embed JavaScript into an HTML page, leaving it inline with the rest of the markup, or to include

JavaScript that exists in an external fi le. The following are key points:

➤ To include external JavaScript files, the src attribute must be set to the URL of the fi le to

include, which may be a file on the same server as the containing page or one that exists on

a completely different domain.

➤ All <script> elements are interpreted in the order in which they occur on the page. The

code contained within a <script> element must be completely interpreted before code in

the next <script> element can begin so long as defer and async attributes are not used.

➤ For nondeferred scripts, the browser must complete interpretation of the code inside

a <script> element before it can continue rendering the rest of the page. For this reason,

<script> elements are usually included toward the end of the page, after the main content

and just before the closing </body> tag.

➤ You can defer a script’s execution until after the document has rendered by using the defer

attribute. Deferred scripts always execute in the order in which they are specified.

➤ You can indicate that a script need not wait for other scripts and also not block the

document rendering by using the async attribute. Asynchronous scripts are not guaranteed

to execute in the order in which they occur in the page.

By using the <noscript> element, you can specify that content is to be shown only if scripting

support isn’t available on the browser. Any content contained in the <noscript> element will not be

rendered if scripting is enabled on the browser.

From:Professional JavaScript for Web Developers (2012)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: