JavaScript Learning Essays

Source: Internet
Author: User

1. Operators
String stitching with "+"
Symbol "| |"

2.arr.length//Array length
STR.SUBSTR (2,3); Reads a few characters from a string, three characters from the third position in Str
Arr.join (); Separates array elements with symbols
Arr.split (); Separating strings by symbols

3. String objects
Str.indexof (); Returns the position of the substring, or 1 if not found
Date Day Object
var date = new Date ();
Dete.getfullyear ();
Math Object//method name directly with
Math.floor (2.3); 2
Math.random (); Back to [0,1]
Array Object

4.window objects
Window.alert (' Pop-up window ');
Window.confirm (' confirmation ');
Window.navigator//Browser information
Window.location.href= ""; Jump to a webpage
Window.history//Browsing history
Window.screen//Screen Object
Window.document//Document object (important)

5. Node operation
Find an Object
Find by ID, return value is Object
document.getElementById (' one ');
Search by label, return value is a collection of objects
document.getElementsByTagName (' P ');
For form elements, you can query by name, and the return value is a list of nodes (object collection).
Document.getelementsbyname (' Form1 ');
Search by class name, return object collection
Document.getelementsbyclassname (' Form1 ');
Find sub-object chlidren,parent
document.getElementById (' one '). ChildNodes;
document.getElementById (' one '). Children; Children non-standard attributes, excluding white space nodes

6. Get the run-time style object
Calculates the style of obj
function GetStyle (obj, attr) {
Return Obj.currentstyle? OBJ.CURRENTSTYLE[ATTR]: window.getcomputedstyle (obj, null) [attr];
}

7. Deleting objects
Steps: 1. Locate the object 2. Find his parent object Parentobj 3.parentobj.removechild (sub-object);
<script>
Function del () {
var lis = document.getelementsbytagname (' li ');
var lastli = lis[lis.length-1];
Lastli.parentNode.removeChild (Lastli);
}
</script>

8. Create a Node
1. Create object 2. Locate the Parent object Parentobj 3.parentobj.addchild (object);
function Add () {
var li = document.createelement (' li ');
var tex = document.createTextNode (' four ');
Li.appendchild (Tex);
document.getElementsByTagName (' ul ') [0].appendchild (LI);
}

9. Violent Operation node
function Add3 () {
var ul = document.getElementsByTagName (' ul ') [0];
ul.innerhtml = ' <li>one</li><li>two</li><li>three</li> ';
}

10. Linkage Menu
DOM Manipulation Events
OnChange ();
09.html

11. Timers
Window.settimeout (' Change () ', 1000); Perform change after 1 seconds ();
Cleartimeout ();
SetInterval (' Change () ', 1000); Change is performed every 1 seconds ();
Clearinterval ();

12. Common Events
OnClick//element when clicked
onfocus//element when getting focus
onblur//element loses focus
onmouseover//Move mouse over element
onmouseout//mouse over element
onsubmit = "Return Change ()"//form is submitted in form
OnLoad//page loading Complete Window.onlod = function change () {} or written in body

13. Event Behavior Structure separation
14.html

14.//Event Object
event = Window.enent | | Event
Event delegate
Ev.target

15. Regular Verification Mailbox
Patt.test (String);
Find the string that matches the regular character in the string
Regular Match Mailbox
Patt.exec (String);


JavaScript Learning Essays

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.