---restore content starts---
- document.write ("str") str is the HTML element to be displayed
- The id attribute can be set for each element in HTML
- Through the script setting function, the function reads the ID in the HTML and modifies the innerHTML of the corresponding element of the ID to achieve the dynamic interface purpose, and then uses the button's OnClick property to start the function.
<body>
<p id= "Demo" > This is a </p>
<script>
function my () {
X=document.getelementbyid ("demo");//Find elements
X.innerhtml= "Hello";//Modify Content
}
</script>
<button type= "button" onclick= "My ()" > click here </button>
</body>
- Click the picture to change the picture
<! DOCTYPE html>
<body>
<script>
function Changeimage ()
{
Element=document.getelementbyid (' MyImage ')
if (Element.src.match ("Bulbon"))
{
Element.src= "/i/eg_bulboff.gif";
}
Else
{
Element.src= "/i/eg_bulbon.gif";
}
}
</script>
<p> tap the light bulb to light or turn off the lamp </p>
</body>
External JavaScript
You can also save the script to an external file. External files typically contain code that is used by multiple Web pages.
The file name extension for external JavaScript files is. js.
To use an external file, set the. js file in the "src" attribute of the <script> tag:
External scripts cannot contain <script> tags.
Introduction to basic knowledge here, query on demand
Getting Started with JavaScript