当前位置: 首页 > 网络学院 > 网页制作基础教程 > HTML > HTML Scripts
Add scripts to HTML pages to make them more dynamic and interactive.
加上脚本来让HTML更具动态性和交互性
Insert a script
插入一脚本
This example demonstrates how to insert a script into your HTML document.
演示怎样在你的页面里插入脚本
Work with browsers that do not support scripts
不支持脚本的浏览器
This example demonstrates how to handle browsers that do not support scripting.
演示怎样针对那些不支持脚本的浏览器做些处理
A script in HTML is defined with the <script> tag. Note that you will have to use the type attribute to specify the scripting language.
在HTML中脚本是用<script>标签定义的.注意得用type属性来指明所用的脚本语言.
<html> <script type="text/javascript"> </body> |
The script above will produce this output:
上面的脚本会生成:
Hello World!
Note: To learn more about scripting in HTML, visit our JavaScript School.
注意:学习更多的HTML脚本,请访问JavaScript School.
A browser that does not recognize the <script> tag at all, will display the <script> tag's content as text on the page. To prevent the browser from doing this, you should hide the script in comment tags. An old browser (that does not recognize the <script> tag) will ignore the comment and it will not write the tag's content on the page, while a new browser will understand that the script should be executed, even if it is surrounded by comment tags.
一些浏览器不支持<srcipt>标签,会将里面的内容以文本的形式显示出来,为了防止这样,你应该将脚本内容用注释的方法来进行隐藏.
JavaScript: <script type="text/javascript"> <!-- document.write("Hello World!") //--> </script> VBScript: |
In addition to hiding the script inside a comment, you can also add a <noscript> tag.
除在注释里隐藏脚本,你还可以添加一个<noscript>标签.
The <noscript> tag is used to define an alternate text if a script is NOT executed. This tag is used for browsers that recognize the <script> tag, but do not support the script inside, so these browsers will display the text inside the <noscript> tag instead. However, if a browser supports the script inside the <script> tag it will ignore the <noscript> tag.
<noscript>标签用来给不能执行的脚本来定义说明文字.这个标签是为那些不能支持<script>标签的浏览器而准备的,不执行脚本而是显示<noscript> 里的文字.
JavaScript: <script type="text/javascript"> <!-- document.write("Hello World!") //--> </script> <noscript>Your browser does not support JavaScript!</noscript> VBScript: |
Tag 标签 | Description 描述 |
---|---|
<script> | Defines a script 定义一个脚本 |
<noscript> | Defines an alternate text if the script is not executed 定义说明 |
<object> | Defines an embedded object 定义布置对象 |
<param> | Defines run-time settings (parameters) for an object 设置对象 |
<applet> | Deprecated. Use <object> instead 不推荐。 |