Javascript-javascript statement \

Source: Internet
Author: User
Tags button type


JavaScript statements

A command issued by a JavaScript statement to the browser. The purpose of the statement is to tell the browser what to do.

The following JavaScript statement outputs the text "Hello World" to the HTML element of the Id= "demo":

document.getElementById ("Demo"). Innerhtml= "Hello World";




Semicolon

Semicolons are used to separate JavaScript statements.

Usually we add semicolons at the end of each executable statement.

Another useful use of semicolons is to write multiple statements in one line.

Tip: You may also see cases with no semicolons.

In JavaScript, concluding sentences with semicolons are optional.



JavaScript Code

JavaScript code (or JavaScript only) is a sequence of javascript statements.

The browser executes each statement in the order in which it is written.

This example will manipulate two HTML elements:




JavaScript is case sensitive.

JavaScript is sensitive to capitalization.

When writing JavaScript statements, be aware of whether to turn off the case toggle key.

The function getElementById is different from the getElementById.

Similarly, variable myvariable and myvariable are also different.
Space



JavaScript ignores extra spaces. You can add spaces to the script to improve its readability. The following two lines of code are equivalent:

var name= "Hello";
var name = "Hello";



Wrapping lines of code

You can wrap lines of code in a text string with backslashes. The following example will display correctly:

document.write ("Hello \
World! ");

However, you cannot fold a line like this:

document.write \
("Hello world!");



Tip: JavaScript is a scripting language. The browser executes the script code on a line-by-row basis when reading the code. For traditional programming, all code is compiled before execution.



The

<!--
JavaScript code block

JavaScript statements are combined in a code block form. The

Block starts with an opening curly brace and ends with a closing curly brace. The purpose of the

block is to make the statement sequence execute together. The

JavaScript function is a typical example of combining statements in blocks.

The following example runs a function that can manipulate two HTML elements:

-->

<! DOCTYPE html>
<body>
<meta http-equiv= "Content-type" content= "text/html charset= Utf-8 "/>
<center>

<p id=" Demo ">i am a paragraph.</p
<p id= "Angel" >i am a div.</p>

<script>
function myFunction ()
{
     document.getelementbyid ("demo"). Innerhtml= "Hello World";
    document.getelementbyid ("Angel"). Innerhtml= "How is it?";
}
</script>

<p>
<button type= "button" onclick= "MyFunction ()" > click here </button
</p>

<p> When you click on the button above, two elements will change. </p>
</center>
</body>
------------------------------------------- -

--------------------------------------------

<! DOCTYPE html>
<meta http-equiv= "Content-type" content= "text/html charset=utf-8"/>
<title></title>
<body>
<center>
<p id = "Demo" >my first </p>
<p id = "Angel" >
<script>
document.getElementById. ("Demo"). Innerhtml= "Hello World";
document.getElementById. ("Angel"). Innerhtml= "How is you!";
</script>
</center>

</body>


Javascript-javascript statement \

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.