JavaScript Learning notes a JavaScript what can do

Source: Internet
Author: User
Tags button type

What is a JavaScript?

JavaScript is an interpreted scripting language that can be inserted into an HTML page and interpreted by the browser.

What can two JavaScript do?

① adding new content to HTML

document.write ("

document.write ("<p>this is a paragraph</p>");

Note: Use document.write during HTML output instead of using this method after the document is loaded, otherwise it will overwrite the entire document.

② Response to Events

<button type= "button" onclick= "alert (' welcome! ')" > Click here </button>

The alert () function is often used for code testing, displaying content and judging whether it is expected.

③ changing HTML content

You can use document.getElementById to get to an HTML element and modify its contents to change the HTML content

X=document.getelementbyid ("demo")//Find elements

X.innerhtml= "Hello JavaScript"; Change Content

④ changing HTML images

You can use document.getElementById (' myimage ') to get a picture element and re-assign a value to the path to the element

element.src= New Path

⑤ changing the style of HTML elements

Changing the style of HTML elements is a variant of changing HTML attributes.

X=document.getelementbyid ("demo")//Find element

X.style.color= "#ff0000";

Validate input

JavaScript is often used to validate user input.

Instance

If IsNaN (x) {alert ("Not Numeric")};

JavaScript Learning notes a JavaScript what can do

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.