JavaScript Primer Basics Summary (3)

Source: Internet
Author: User

/*
Basic JavaScript Learning Summary
This summary uses the DW to write, in order to debug conveniently, will affect the test part to write in the annotation form ****/
All tests are shown with the alert () function

1, JavaScript special characters//in JavaScript you can use backslashes to represent a special character, see example
Code output
\ ' Single quotation mark
\ "Double quotation marks
\& and No.
\ \ counter Slash
\ n line break
\ r return character
\ t tab
\b Backspace
\f Page Break

2. JavaScript guidelines//A) JavaScript is case sensitive, my and my are different
b) JavaScript ignores more spaces in the code,
such as: name = "a" and name= "a" are the same, so you can use a space to make your code more beautiful
c) Allow this line break in JavaScript code
document.write ("Hello \
world!)

3, JavaScript Object//a) JavaScript is an object-oriented language, we can create our own objects, an object has its own properties and methods
b) JavaScript internal objects
var txt = "Hello"; We can use Txt.length to get the txt length (length is the property of the object txt)
Txt.touppercase () We can call the TXT object in such a way that the lowercase letters in TXT are capitalized
4), string declaration string str; Use Str.length to get the length of a string
Call Str.big (), Str.small (), Str.blink () and other methods to modify the style of the string
Call Str.indexof () to get the first occurrence of a character in the string
For more information, please refer to http://www.w3school.com.cn/jsref/jsref_obj_string.as
5), date declaration var date = new Date (); function Fundate () {
var t = new Date ();//Get a new date, consistent with the current system time
T.setfullyear (1993,3,23);//Set your own date, note that the month should be set by 0-11
T.setdate (T.getdate () +5);//Set the time to 5 days after the current time.
T.todatestring ();//Convert to String by UTC
var temp = new Date ();
Temp > t; Two dates can be directly compared to the size of
Alert (t);
}
For more information, please refer to http://www.jb51.net/w3school/js/jsref_obj_date.htm
6) Array object function Funarray () {
var arr = new Array ();//Declaration instantiation Array
Arr[0] = "123";
ARR[1] = "456";
Arr.sort ();
document.getElementById ("Array"). Innerhtml=arr[1];
}
Common methods for arrays
1, Arr1.concat (ARR2); merging two arrays
2, Arr.join (".") Links the contents of the array to a string, which is used in the middle. Separated
3, arr.sort () Ann literally sort
4, Arr.sort (sortnumber) function Sortnumber (A, b) {return a-A;} Mate functions can be sorted by size of digital content
For more information, please refer to http://www.w3school.com.cn/jsref/jsref_obj_array.asp
7) Boolean object function Funboolean () {
var T1 = Boolean ();
var t2 = Boolean (0);
var t3 = Boolean (1);
var T4 = Boolean ("");
var t5 = Boolean (null);
var T6 = Boolean (NaN);
var t7 = Boolean ("false");
var T8 = Boolean (TRUE);
var T9 = Boolean ("TTT");
var txt = "0 logical value:" +t2+ "\ n" + "1 logical value:" +t3+ "\ n" + "logical value of empty string:" +t4+ "\ n" + "null Logical value:" +t5+ "\ n";
txt + = "Nan logical value:" +t6+ "\ n" + "\" false\ "logical Value:" +t7+ "\ n" + "no logical value of any initial value:" +t1+ "\ n" + "true logical value:" +t8+ "\ n" + "arbitrary string logical value:" +t9+ "\ n" ;
alert (TXT);
}
For more information, please refer to http://www.w3school.com.cn/jsref/jsref_obj_boolean.asp
8) Math object function Funmath () {
var T1 = Math.Round (0.6);//Gets the rounded value of the parameter
var t2 = math.random ();//Get a decimal between 0-1
var t3 = Math.max (5,4);//Get the number of the larger dozen in two numbers
var t4 = math.min ( -4.4,4);//Get the smaller number in two numbers
var txt = "T1 =" +t1+ ", t2 =" +t2+ ", T3 =" +t3+ ", T4 =" +T4;
document.getElementById ("Math"). InnerHTML = txt;
}
For more information, please refer to HTTP://WWW.JB51.NET/W3SCHOOL/JS/JSREF_OBJ_MATH.HTM1
9) Regular expression//define regular rule var pat = new RegExp ("rule");
Common methods Demo
function Funregexp () {
var pat = new RegExp ("e.*e");
var T1 = pat.test ("Esdjkfe");//retrieves the substring in the string that knows the regular
var t2 = pat.exec ("EJDKLSJ");//Retrieves and returns a string, none returns null
Pat.compile ("E");//Modify existing regular rules
var t3 = pat.test ("eeee");
var txt = "T1 =" +t1+ ", t2 =" +t2+ ", T3 =" +T3;
alert (TXT);
}
For more information, please refer to http://www.w3school.com.cn/jsref/jsref_obj_regexp.asp
HTML dom/*html DOM is the standard (the English abbreviation for the HTML Document Object model, document object models for HTML).
The HTML DOM defines a series of standard objects for HTML, as well as a standard way to access and manipulate HTML documents.
Through the DOM, you can access all the HTML elements, along with the text and attributes they contain. The content can be repaired and deleted, and new elements can be created.
The HTML DOM is independent of the platform and programming language. It can be used by any programming language such as Java, JavaScript, and VBScript.
For more information, please refer to http://www.w3school.com.cn/jsref/dom_obj_document.asp*/


JavaScript Primer Basics Summary (3)

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.