码迷,mamicode.com
首页 > 编程语言 > 详细

JavaScript在网页中的位置

时间:2015-06-28 12:46:48      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:javascript在网页中的位置

     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)

JavaScript在网页中的位置

标签:javascript在网页中的位置

原文地址:http://blog.csdn.net/doctor_who2004/article/details/46670025

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!