JS-JavaScript Study Notes (1): javascript Study Notes

Source: Internet
Author: User

JS-JavaScript Study Notes (1): javascript Study Notes
JavaScript


1. document Output: document. write () can output characters, expressions, html tags, functions


2. Any type and string addition will be converted to the string type.
For example, var I = 5; var j = "5"; var k = I + j; Result: k = 55


3. Operator priority (from high to low)
Arithmetic Operators-> comparison operators-> logical operators-> "=" value assignment operators. If operations at the same level are performed in the left-to-right order, the multi-layer brackets are left-to-right.


4. Events:
Onclick,
Onmouseover,
Onmouseout move with the mouse,
Onfocus gets focus,
Onblur loses focus,
Onselect selected,
The onchange text box is changed,
Onload loading,
Onunload uninstall
5. built-in objects


Date object,
Get/setTime (); time
Get/setDate (); Date
GetDay (); week
String object,
CharAt (index); get the character at the specified position;
IndexOf (substring, startPos); returns the position where the specified string appears for the first time;
Split (separator, limit); string split into character Arrays
Substring (startPos, endPos); extract the string that the string is intermediary between two downlink
Subsrt (startPos, length); extract the specified number of strings starting from the startPos position in the string


Math object,
Ceil (x); rounded up
Floor (x); rounded down
Round (x); rounding
Random (); random Number


Array object,
Concat (array1.... arrayN); array connection
Join (separator); specify a separator to connect to an array element
Reverse (); reverse the order of array elements
Slice (start, end); returns the specified element from an existing array
Sort (method function); sorts arrays in a certain order
Example:
<Script type = "text/javascript">
Function sortNum (a, B ){
Return a-B;
// In ascending order, such as descending order, convert "a-B" to "B-"
}
Var myarr = new Array ("80", "16", "50", "6", "100", "1 ");
Document. write (myarr + "<br> ");
Document. write (myarr. sort (sortNum ));
</Script>

6. browser objects

** Browser Object Model (BOM)

(1). window object


(2). javascript Timer
A. Timer var I = setInterval (Code, interaction time); During execution, the code is executed at the specified time after loading the page.
B. Cancel the time clearIntercal (I );
C. The setTimeout (Code, latency time) timer executes an expression once after the specified delay after loading.

D. Cancel the clearTimeout timer (ID value returned by setTimeout)


(3). The History Object-the history object records the pages (URLs) that the user has browsed, and allows the browser to move forward and backward in similar navigation.
A. window. history. [attribute | method]
B. Return the number of URLs in the browser history list.

C. method: back (), load the previous URL in the History list, which is equivalent to go (-1); forward () loads the next URL in the History list, which is equivalent to go (1 ); go (number-the relative location of the URL to be accessed in the list) loads the page specified in the History List


(4). Location object -- location is used to obtain or set the URL of the form, and can be used to parse the URL.



(5). the Navigator object-the Navigator object contains information about the browser, which is usually used to detect the version of the browser and the operating system.


(6). screen Object -- screen object is used to obtain the user's screen information.


7. DOM (Document Object Model) Document Object Model-Defines standard methods for accessing and processing HTML documents. DOM presents HTML documents as a tree (node tree) with elements, attributes, and text ).

(1). getAttribute (name) method-get the attribute value through the attribute name of the element node.
Syntax:
ElementNode. getAttribute (name)
Note:
1. elementNode: The Element Node obtained by getElementById () and getElementsByTagName.
2. name: attribute name of the element node to be queried
(2). setAttribute () method-Add a new attribute with a specified name and value, or set an existing attribute to a specified value.
Syntax:
ElementNode. setAttribute (name, value)
Note:
1. name: name of the property to be set.
2. value: the property value to be set.
Note:
1. Set the specified attribute to the specified value. If no property with the specified name exists, this method creates a new property.
2. Similar to the getAttribute () method, the setAttribute () method can only call functions through element node objects.
(3) visible area size of the browser window
A Practical JavaScript solution for different browsers:
Var w = document.doc umentElement. clientWidth
| Document. body. clientWidth;
Var h = document.doc umentElement. clientHeight
| Document. body. clientHeight;
(4) web page size scrollHeight
Browser compatibility
Var w=document.doc umentElement. scrollWidth
| Document. body. scrollWidth;
Var hsf-document.doc umentElement. scrollHeight
| Document. body. scrollHeight;
Note: Case Sensitive
ScrollHeight and scrollWidth can also obtain the actual height and width of the content in the Dom element.


(5) webpage size offsetHeight
OffsetHeight = clientHeight + scroll bar + border.
Browser compatibility
Var w = document.doc umentElement. offsetWidth
| Document. body. offsetWidth;
Var h = document.doc umentElement. offsetHeight

| Document. body. offsetHeight;


Reference: http://www.imooc.com/learn/10

Learning Website: http://www.dreamdu.com/javascript/core/

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.