Getting Started with JavaScript

Source: Internet
Author: User
Tags button type

---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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.