JavaScript QuickStart Chapter I basics (i.)

Source: Internet
Author: User
Tags array sort set time
The importance of JavaScript is self-evident, a friendly and excellent site is inseparable from JS, let us Open JS trip it. I'll talk about jquery.
JavaScript is a literal-translation scripting language:is a dynamic type, a weak type, a prototype based language, and a built-in support type. Its interpreter, known as the JavaScript engine, is widely used as a scripting language for clients, and is used in HTML (an application under standard Universal Markup Language) to add dynamic functionality to HTML Web pages. The development of the El expression may be encountered in the JS code does not work, because two are not at a level, the solution there are many online, in the future, I will be encountered in the project errors and solutions sorted out.
JavaScript Basic Features:One is an interpretative scripting language (code does not precompile) two. is primarily used to add interaction behavior to HTML (one application under Hypertext Markup Language) three. Can embed HTML page directly, but write individual JS file is advantageous to the separation of structure and behavior
JavaScript Applications:I. Embed dynamic text in an HTML page. Two. Respond to browser events. Three. Read and write HTML elements. Four. Validate data before data is submitted to the server. Five. Monitor visitor's browser information. Six. Control cookies, including creation and modification.
After a general understanding of JS, let's take a look at its syntax. My personal feeling is similar to Java, so I'll talk about it briefly. JS all data types are defined with Var without brain (whether it is string,boolean,float,int with Var)
JS definition ArrayOne-dimensional array: var arr = new Array (8), length 8 without value display undefine, although the length is limited, but can also extend the assignment: arr[0]=0; Arr[1]=1; arr[2]=2; var arr = new Array (0,1,2); Create and assign var arr = [0,1,2]; Enter an array directly, also known as the length of an array of literal arrays: arr.length; Two-dimensional array: var arr = [[1,2,3],[4,5]] first defines a one-dimensional array and assigns the value var arr = new Array (); for (var i = 0; i < 2; i++) {var [i] = new Array ();
for (var j = 0; J < 3; J + +) {var [i][j] = i + j;
}
The array Connection concat () is used to concatenate two or more arrays, returning a new array without altering the original array arr.concat (Array1,array2,..., Arrayn);
<script type= "Text/javascript" >
    var myarr1= new Array ("010")
    var myarr2= new Array ("-", "84697581");
    document.write (Myarr1.concat (MYARR2));
</script>
Join () puts all the elements of an array into a string, separated by the specified delimiter. Default is comma
<script type= "Text/javascript" >
    var myarr1= new Array ("", "010")
    var myarr2= new Array ("84697581");
    var myarr3= myarr1.concat (MYARR2);
    document.write (Myarr3.join ("-") + "<br>");
    document.write (Myarr3.join ());
</script>
Reverse array element order Arr.reverse ();
<script type= "Text/javascript" >
   var myarr1= ["I", "Love", "You"];
   document.write (Myarr1.reverse ());
</script>
The selected element Arr.slice (start,end); 1. Returns a new array, from start to End-1 2. The method does not modify the array, but instead returns a child array of 3. The negative number is the selection element from the tail start
<script type= "Text/javascript" >
   var myarr1= ["IT", "Dragon", "blog"];
   document.write (Myarr1.slice (1));
</script>
Array sort Arr.sort (method function); Sequence ordering of default Unicode codes
<script type= "Text/javascript" >
   function Sortnum (a,b) {return
    b-a;
   }
var Myarr = new Array ("6", "N", "1", "+");
document.write (Myarr.sort (Sortnum));
</script>

String String ObjectReturns the character String.charat (index) of the specified position;
<script type= "Text/javascript" >
  var mystr= "I Love javascript!"
  document.write (Mystr.charat (mystr.length-1));
</script>
Returns the position of the specified string for the first occurrence string.indexof (substring,startpos); SUBSTRING: is the string that needs to be retrieved startpos: optional argument, starting at startpos position. If found, return to the first occurrence of the position, no return-1
<script type= "Text/javascript" >
  var mystr= "Hello world!"
  document.write (Mystr.indexof ("O", 5));
</script>
String segmentation string.split (separator,limit); Separator: Required, from the place specified in this parameter segmentation limit: Optional parameters, the number of partitions; If you do not set it can be infinitely divided
<script type= "Text/javascript" >
var mystr= "86-010-85468578";
document.write (Mystr.split ("-") + "<br/>");
document.write (Mystr.split ("") + "<br/>");
document.write (Mystr.split ("", 3));
</script>
Extract string string.substring (Startpos,stoppos); 1. The returned content is from start, to Stop-1 2. If the argument start and stop are equal, an empty 3 is returned. If start is larger than stop, this method swaps two parameters by default
<script type= "Text/javascript" >
var mystr= "Hello world!"
document.write (mystr.substring (6) + "<br/>");
document.write (mystr.substring (0,6));
</script>
Extracts the specified number of strings string.substr (startpos,length); Startpos: Required, the starting position of the substring to extract must be value length: optional, extracted string length, default to Tail 1. If the parameter startpos is a negative number, it is calculated from the end of the string, such as-1 is the last character 2. If the absolute value of the argument startpos negative number is greater than the string length, the argument becomes 0
<script type= "Text/javascript" >
var mystr= "Hello world!";
document.write (Mystr.substr (0,5) + "<br/>");
document.write (Mystr.substr ( -6,6));
</script>

Date Object:var currenttime= new Date ();  Gets the current time var d = new Date (2015,7,2); Set is July 2, 2015 var d = new Date ("Oct 1,2015"); Set the October 1, 2015 more methods can refer to the following figure
Set year
<script type= "Text/javascript" >
var mydate=new Date (); 
var myyear=mydate.getfullyear ();
document.write (mydate);
document.write ("Year:" +myyear);
</script>
Set time
<script type= "Text/javascript" >
 var mydate=new Date ();
  document.write ("Current Time:" +mydate+ "<br>");
  Mydate.settime (Mydate.gettime ()  + 2* * * 1000);
  document.write ("Two hours Delayed:" + mydate);
</script>

More dry goods wait for you to get http://www.itit123.cn/














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.