JS use method and Function summary 1th/4 page _javascript Tips

Source: Internet
Author: User
1 Creating script blocks
1: <script language= "JavaScript" >
2:javascript Code goes here
3: </script>
2 Hide Script code
1: <script language= "JavaScript" >
2: <!--
3:document.write ("Hello");
4://-->
5: </script>
Do not execute related code in browsers that do not support JavaScript
3 When the browser does not support the display
1: <noscript>
2:hello to the Non-javascript browser.
3: </noscript>
4 Linking external script files
1: <script language= "JavaScript" src= "/" Filename.js "></script>
5 Annotation Scripts
1://This is a comment
2:document.write ("Hello"); This is a comment
3:/*
4:all of this
5:is a Comment
6: */
6 output to browser
1:document.write ("<strong>Hello</strong>");
7 Defining variables
1:var myvariable = "some value";
8 String Addition
1:var myString = "String1" + "String2";
9 String Search
1: <script language= "JavaScript" >
2: <!--
3:var myvariable = "Hello There";
4:var thereplace = Myvariable.search ("there");
5:document.write (Thereplace);
6://-->
7: </script>
10 String Replacement
1:thisvar.replace ("Monday", "Friday");
11 formatting strings
1: <script language= "JavaScript" >
2: <!--
3:var myvariable = "Hello There";
4:document.write (Myvariable.big () + "<br>");
5:document.write (Myvariable.blink () + "<br>");
6:document.write (Myvariable.bold () + "<br>");
7:document.write (myvariable.fixed () + "<br>");
8:document.write (Myvariable.fontcolor ("red") + "<br>");
9:document.write (Myvariable.fontsize ("18pt") + "<br>");
10:document.write (Myvariable.italics () + "<br>");
11:document.write (Myvariable.small () + "<br>");
12:document.write (Myvariable.strike () + "<br>");
13:document.write (Myvariable.sub () + "<br>");
14:document.write (Myvariable.sup () + "<br>");
15:document.write (Myvariable.tolowercase () + "<br>");
16:document.write (Myvariable.touppercase () + "<br>");
17:
18:var firststring = "My String";
19:var finalstring = Firststring.bold (). toLowerCase (). FontColor ("Red");
://-->
</script>
12 Creating an array
1: <script language= "JavaScript" >
2: <!--
3:var myarray = new Array (5);
4:myarray[0] = "Entry";
5:MYARRAY[1] = "Second Entry";
6:MYARRAY[2] = "Third Entry";
7:MYARRAY[3] = "Fourth Entry";
8:myarray[4] = "Fifth Entry";
9:var Anotherarray = new Array ("Entry", "Second Entry", "Third Entry", "Fourth Entry", "fifth Entry");
Ten://-->
One: </script>
13 Array Sorting
1: <script language= "JavaScript" >
2: <!--
3:var myarray = new Array (5);
4:myarray[0] = "Z";
5:MYARRAY[1] = "C";
6:MYARRAY[2] = "D";
7:MYARRAY[3] = "a";
8:MYARRAY[4] = "Q";
9:document.write (Myarray.sort ());
Ten://-->
One: </script>
14 Split String
1: <script language= "JavaScript" >
2: <!--
3:var myvariable = "A,b,c,d";
4:var Stringarray = Myvariable.split (",");
5:document.write (Stringarray[0]);
6:document.write (stringarray[1]);
7:document.write (stringarray[2]);
8:document.write (Stringarray[3]);
9://-->
: </script>
15 Pop-up warning message
1: <script language= "JavaScript" >
2: <!--
3:window.alert ("Hello");
4://-->
5: </script>
16 Pop-up confirmation box
1: <script language= "JavaScript" >
2: <!--
3:var result = Window.confirm ("Click OK to continue");
4://-->
5: </script>
17 Defining functions
1: <script language= "JavaScript" >
2: <!--
3:function Multiple (number1,number2) {
4:var result = Number1 * NUMBER2;
5:return result;
6:}
7://-->
8: </script>
18 calling JS function
1: <a href= "#" onclick= "functionname ()" >link text</a>
2: <a href= "/" Javascript:functionname "()" >link text</a>
19 Execute function After page load completes
1: <body onload= "functionname" (); >
2:body of the page
3: </body>
20 piece Judgment
1: <script>
2: <!--
3:var Userchoice = window.confirm ("Choose OK or Cancel");
4:var result = (Userchoice = = True)? "OK": "Cancel";
5:document.write (result);
6://-->
7: </script>
21 specified number of cycles
1: <script>
2: <!--
3:var myarray = new Array (3);
4:myarray[0] = "Item 0";
5:MYARRAY[1] = "Item 1";
6:MYARRAY[2] = "Item 2";
7:for (i = 0; i < myarray.length; i++) {
8:document.write (Myarray[i] + "<br>");
9:}
Ten://-->
One: </script>
22 setting Future execution
1: <script>
2: <!--
3:function Hello () {
4:window.alert ("Hello");
5:}
6:window.settimeout ("Hello ()", 5000);
7://-->
8: </script>
23 timed execution function
1: <script>
2: <!--
3:function Hello () {
4:window.alert ("Hello");
5:window.settimeout ("Hello ()", 5000);
6:}
7:window.settimeout ("Hello ()", 5000);
8://-->
9: </script>
24 Cancel timed execution
1: <script>
2: <!--
3:function Hello () {
4:window.alert ("Hello");
5:}
6:var mytimeout = window.settimeout ("Hello ()", 5000);
7:window.cleartimeout (mytimeout);
8://-->
9: </script>
25 executing functions on page uninstall
1: <body onunload= "functionname" (); >
2:body of the page
3: </body>
Current 1/4 page 1234 Next read the full text

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.