HTML script is also called a script in Chinese. It is a way for HTML to add other scripts. Commonly seen are JavaScript or VBScript. The standard HTML script script declaration must include a start tag and an end tag. For example, if you add JavaScript to Code, you can start with <script type="text/javascript"> and end with </script>. Almost all mainstream browsers support the function of HTML script, but if the browser’s JavaScript is turned off , It cannot be used. Also note that each script may have different rendering effects in different browsers. Depending on the degree of browser support, designers usually need to test the beta version on multiple browsers.
HTML script script basic syntax<script type="text/javascript">
...write the content of javascript here...
</script>
The basic syntax is javascript as an example. HTML scripts also have ways to declare other script types, such as text/ecmascript, application/ecmascript, application/javascript, text/vbscript. The following is a table of common script attributes.HTML script script attributesAttributes | Property value and description |
type | Used to specify the type of script, the syntax is such as <script type="text/javascript">.
|
src | Set the embedded external script file link.
|
charset | Used to set the encoding method of the embedded external script file.
|
language | The syntax is like <script language="javascript">, and the function is similar to type. It is recommended to use type.
|
defer | Not all browsers support the defer attribute.
|
HTML script script example 1. Write JavaScript syntax<script type="text/javascript">
document.write('Welcome to Wibibi');
</script>
The above example outputWelcome to Wibibi
This is a very simple standard JavaScript writing method. It starts with <script type="text/javascript"> and ends with </script>. You can write the required content in the middle, and the start tag can also be written as <script language="javascript" > example syntax is DOM 's document.write to write "Welcome Wibibi" string.HTML script script example 2: Embed a JavaScript grammar<script src="tset.js" charset="UTF-8"></script>
The above example outputWelcome to Wibibi
If our script is written as a separate file and embedded in a different web page, we must use the scr attribute to embed it. For example, save sample one as a test.js file and place it under the root directory of the web page, and use it in sample two By embedding it with the scr attribute, the output text content of the example can be displayed in the file of example 2. This technique is also used by many large websites. The advantage is that the script management is more efficient. In this example, we also added charset attribute, set the embedded script file encoding to UTF-8 universal code. It is recommended that designers use the same encoding when planning the overall web page encoding to avoid not work.
Post a Comment
0 Comments