W3cschool's JavaScript Learning __w3cschool Learning

Source: Internet
Author: User
implementation of 1.JSThe JS script must be located between the <script> and </script> tags the script tag can be placed in the head or body tag of the HTML file. Generally I like to put it in the head. A. Put it in the head, for example
<body> <p id= "Demo" > A Paragraph </p>
<button type= "button" onclick= "MyFunction ()" > click here </button>
</body>
<body> <p id= "Demo" > A Paragraph </p>
<button type= "button" onclick= "MyFunction ()" > click here </button>
The <!-script is placed on the last side of the body-> <script> function MyFunction () {document.getElementById ("demo"). Inn         Erhtml= "My I-JavaScript Function"; } </script>
</body>
function MyFunction () {document.getElementById ("demo"). Innerhtml= "My I-JavaScript Function";}
Here to introduce the external JS file:
<body> <p id= "Demo" > A Paragraph </p>
<button type= "button" onclick= "MyFunction ()" > click here </button> </body>
Note: Whether externally or directly embedded in HTML, each script tag is publicly accessible to each other in the code, so multiple script tags can be synthesized into a script tag pair. External scripts cannot contain <script> tags.
output of 2.JSA. Manipulating HTML elements: using ID attributes to mark HTML elements, and then using IDs to access the elements such as: <body> <p id= "Demo" > My Paragraph. </p> </body>
B. Writing information to HTML documents <body> Note: If you execute document.write after the document has finished loading, the entire HTML page will be overwritten: 3. NoteThe comments in the JS code use://This is a single-line comment or/** this is a multiline comment/html comment used: <!-html comments > variables in the 4.JSBecause JS is a weak data type language, declaring variables using the var keyword can be. var carname= "Volvo";
var name= "Gates", age=56, job= "CEO"; Note: If a variable is declared but not assigned, the value of the variable is undefined, the variable can be declared repeatedly, and if it is not assigned again when it is declared, it will not change its value. If we assign a value to a variable that does not use the keyword VAR declaration, then the variable becomes a global variable. data types in 5.JSnumeric type, var x = 6; If the prefix is 0, JavaScript interprets numeric constants as octal numbers, and if the prefix is 0 and "X", it is interpreted as a hexadecimal number. var y=0377; var Z=0xff; Some common attributes of your property constants and methods, Properties:MAX value MIN value NEGATIVE infinitive POSITIVE infinitive NaN prototype constructor Method:Toexponential () toFixed () toprecision () toString () valueof ()
String type,
var carname= "Bill Gates";
var carname= ' Bill Gates ';
String Object Properties
Property Description
Constructor A reference to the function that created the object
Length Length of string
Prototype Allows you to add properties and methods to an object
String Object method The
method Description
anchor () creates an HTML anchor.
big () displays a string in a large font. The
Blink () displays a flashing string. The
Bold () displays the string in bold. The
charAt () returns the character at the specified position. The
charcodeat () returns the Unicode encoding of the character at the specified location.
concat () connection string. The
fixed () displays the string in typewriter text. The
fontcolor () uses the specified color to display the string. The
fontsize () uses the specified dimensions to display the string. The
fromcharcode () creates a string from a character encoding. The
indexOf () retrieves the string. The
italics () uses italics to display a string. The
lastindexof () searches the string forward from behind.
link ()

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.