English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
JavaScript makes HTML pages more dynamic and interactive; some web effects can be realized through JavaScript.
Insert a script
How to insert scripts into an HTML document.
Use the <noscript> tag
How to deal with browsers that do not support or disable scripts.
The <script> tag is used to define client-side scripts, such as JavaScript.
The <script> element can contain script statements or point to an external script file through the src attribute.
JavaScript is most commonly used for image operations, form validation, and dynamic content updates.
The following script will output "Hello World!" to the browser:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <script> document.write("Hello World!") </script> </body> </html>Test to see ‹/›
The <noscript> tag provides alternative content when scripts cannot be used, such as when scripts are disabled in the browser or when the browser does not support client-side scripts.
The <noscript> element can contain all elements that can be found in the body element of a normal HTML page.
The <noscript> element is displayed only when the browser does not support scripts or when scripts are disabled:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <script> document.write("Hello World!") </script> Sorry, your browser does not support JavaScript!/noscript> <p>Browsers that do not support JavaScript will use the content (text) defined in the <noscript> element as a substitute.</p> </body> </html>Test to see ‹/›
JavaScript Example Code:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <p> JavaScript can use document.write to directly write to the HTML output stream: </p> <script> document.write("<h1This is an H1Title/h1> document.write("<p>This is a paragraph.</p> </script> <p> You can only use <strong>document.write</strong> in the HTML output stream./strong>。 If you use it after the document has been loaded (for example, in a function), it will overwrite the entire document. </p> </body> </html>Test to see ‹/›
<html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <h1>My first JavaScript script</h1> <p id="demo"> JavaScript can trigger events, just like a button click.</p> <script> function test_js() { document.getElementById("demo").innerHTML="Hello JavaScript(oldtoolbag.com)!"; } </script> <button type="button" onclick="test_js()">Click Me</button> </body> </html>Test to see ‹/›
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Basic Tutorial(oldtoolbag.com)</title> </head> <body> <h1>My first JavaScript</h1> <p id="demo"> JavaScript can change the style of HTML elements (oldtoolbag.com)。 </p> <script> function test_js() { x=document.getElementById("demo") // Find Element x.style.color="#ff3300"; // Change Style } </script> <button type="button" onclick="test_js()">Click here</button> </body> </html>Test to see ‹/›
Tag | Description |
<script> | Client-side script |
<noscript> | Text that is output by browsers that do not support scripts |