当前位置: 首页 > 网络学院 > 网页制作基础教程 > HTML > HTML <script>标签
Defines a script, such as a JavaScript.
定义一脚本,比如像JavaScript
The "language" attribute of the script element was deprecated in HTML 4.01.
HTML4.01不推荐script元素的"language"属性
The "language" attribute of the script element is not supported in XHTML 1.0 Strict DTD.
XHTML1.0严密型DTD不支持script元素的"language"属性
Note: Code within this element is executed immediately when the page is loaded, if it is not in a function. Script that appears after a <frameset> tag will be ignored.
注意:当页面被加载的时候这个元素里的非函数代码会立即执行。出现在<frameset>标签后的脚本会被忽视。
代码 | 输出 |
---|---|
<script type="text/javascript"> document.write("Hello World!") </script> |
DTD indicates in which DTD the attribute is allowed. S=Strict, T=Transitional, and F=Frameset.
下表中的DTD列指明了被支持的DTD属性。S=Strict(精确的),T=Transitional(传统的),F=Frameset(框架)
属性 | 值 | 描述 | DTD |
---|---|---|---|
type | text/ecmascript text/javascript text/jscript text/vbscript text/vbs text/xml | Indicates the MIME type of the script 指出脚本的MIME类型 | STF |
属性 | 值 | 描述 | DTD |
---|---|---|---|
charset | charset | Defines the character encoding used in script 定义在脚本中使用的字符编码 | STF |
defer | defer | Indicates that the script is not going to generate any document content. The browser can continue parsing and drawing the page 表明该脚本不再继续生成任何文档内容。浏览器将继续解析并绘制页面 | STF |
language | javascript livescript vbscript other | Specifies the scripting language. Deprecated. Use the type attribute instead. 指定脚本语言。不推荐使用。推荐用type属性 | TF |
src | URL | Defines a URL to a file that contains the script (instead of inserting the script into your HTML document, you can refer to a file that contains the script) 定义一个目标URL或是一个文件,其包含脚本的内容。 | STF |
xml:space |
For a full description, go to Standard Attributes.
查看完整的属性
NONE
无
Insert a script
How to insert a script into your HTML document.
如何在HTML中加入脚本
Work with browsers that do not support scripts
How to handle browsers that do not support scripting.
为无法支持脚本的浏览器做些处理