JavaScript Basic Knowledge Collation _ Basics

Source: Internet
Author: User

1 Creating script blocks
Program code

Copy Code code as follows:

<script language= "JavaScript" >
The JavaScript code is written in this area
</script>

2 Hide Script code
Program code
<script language= "JavaScript" > <!-document.write ("Hello"); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

Do not execute related code in browsers that do not support JavaScript
3 When the browser does not support the display
Program code
Copy Code code as follows:

<noscript>
Hello to the Non-javascript browser.
</noscript>

4 linking external script files
Program code
Copy Code code as follows:

<script language= "JavaScript" src= "/" Filename.js "></script>

5 Annotation Scripts
Program code
Copy Code code as follows:

This is a comment
document.write ("Hello"); This is a comment
/*
All of this
is a comment
*/

6 output to browser
Program code
Copy Code code as follows:

document.write ("<strong>hello jb51 .net</strong>");

7 Defining variables
Program code
Copy Code code as follows:

var myvariable = "some value";

8 String Addition
Program code
Copy Code code as follows:

var myString = "String1" + "String2";

9 String Search
Program code
<script language= "JavaScript" > <!-var myvariable = "Hello There"; var thereplace = Myvariable.search ("there"); document.write (Thereplace); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

10 String Replacement
Program code
Copy Code code as follows:

Thisvar.replace ("Monday", "Friday");

11 formatting strings
Program code
<textarea id="runcode65537"><script language= "JavaScript" > <!-var myvariable = "Hello There"; document.write (Myvariable.big () + ""); document.write (Myvariable.blink () + ""); document.write (Myvariable.bold () + ""); document.write (myvariable.fixed () + ""); document.write (Myvariable.fontcolor ("red") + ""); document.write (Myvariable.fontsize ("18pt") + ""); document.write (Myvariable.italics () + ""); document.write (Myvariable.small () + ""); document.write (Myvariable.strike () + ""); document.write (Myvariable.sub () + ""); document.write (Myvariable.sup () + ""); document.write (Myvariable.tolowercase () + ""); document.write (Myvariable.touppercase () + ""); var firststring = "My String"; var finalstring = Firststring.bold (). toLowerCase (). FontColor ("Red"); -> </script></textarea>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

12 Creating an array
Program code
<script language= "JavaScript" > <!-var myarray = new Array (5); Myarray[0] = "Entry"; MYARRAY[1] = "Second Entry"; MYARRAY[2] = "Third Entry"; MYARRAY[3] = "Fourth Entry"; Myarray[4] = "Fifth Entry"; var anotherarray = new Array ("Entry", "Second Entry", "Third Entry", "Fourth Entry", "fifth Entry"); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

13 Array Sorting
Program code
<script language= "JavaScript" > <!-var myarray = new Array (5); Myarray[0] = "Z"; MYARRAY[1] = "C"; MYARRAY[2] = "D"; MYARRAY[3] = "a"; MYARRAY[4] = "Q"; document.write (Myarray.sort ()); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

14 Split String
Program code
<script language= "JavaScript" > <!-var myvariable = "A,b,c,d"; var Stringarray = Myvariable.split (","); document.write (Stringarray[0]); document.write (stringarray[1]); document.write (stringarray[2]); document.write (Stringarray[3]); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

15 Pop-up warning message
Program code
<script language= "JavaScript" > <!-window.alert ("Hello"); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

16 Pop-up confirmation box
Program code
<script language= "JavaScript" > <!-var result = window.confirm ("Click OK to continue"); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

17 Custom Functions
Program code
<script language= "JavaScript" > <!-function Multiple (number1,number2) {var result = Number1 * NUMBER2; return result; }//-> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

18 Calling JS function
Program code
Copy Code code as follows:

<a href= "#" onclick= "functionname ()" >link text</a>
<a href= "/" Javascript:functionname "()" >link text</a>

19 Execute function After page load completes
Program code
Copy Code code as follows:

<body onload= "functionname ();" >
The body of the page
</body>

20 piece Judgment
Program code
<script> <!-var userchoice = window.confirm ("Choose OK or Cancel"); var result = (Userchoice = = True)? "OK": "Cancel"; document.write (result); -> </script>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

21 specified number of cycles
Program code
<script> <!-var myarray = new Array (3); Myarray[0] = "Item 0"; MYARRAY[1] = "Item 1"; MYARRAY[2] = "Item 2"; for (i = 0; i < myarray.length i++) {document.write (Myarray[i] + ""); }//->
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]

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.