(Updating) JavaScript learning notes

Source: Internet
Author: User

1. Add events in JS

$ ("F"). attachevent ("onclick", a); $ ("F"). detachevent ("onclick", );

$ ("F"). onclick = A; difference: the former can add multiple event functions, and the latter can only add one event function.

You can pass in the event parameter or not

Function A (o)
{
VaR n = Window. event. keycode;
If (n <48 | n> 57)
Window. event. returnvalue = false;

Alert (O. type );
}

<Input type = "text" id = "DD" onkeypress = "A (event);"/>

2. attributes and methods of events in IE

Altkey button cancelbubble clientx clienty ctrlkey fromelement keycode offsetx offsety

Repeat returnvalue screenx screeny shiftkey srcelement toelement Type X Y

3. Common events

Load unload abort error select change submit reset resize scroll focus blur

4.

XHTML: Invalid parameter document.doc umentelement. scrolltop document.doc umentelement. scrollleft

HTML: Too Many Doc ument. Body. scrolltop document. Body. scrollleft

5.

Style.css text style. width = 10 currentstyle is a read-only style $ ("SS"). innertext = $ ("SS"). innertext; you can delete all your HTML tags.

Outertext outerhtml

DOM: style. getpropertyvalue ("backgroud-color") style. Item (0) style. removeproperty ("backgroud-color ")

6. Scope

VaR o = document. body. createTextRange (); var OP1 = $ ("p1" );o.movetoelementtext(op1);alert(o.html text); displays the content of the entire P1: <p id = "p1"> <B> Hello </B> world </P>

VaR o = document. body. createTextRange (); O. findtext ("hello"); O. TEXT = "111"; alert (O. text); replaceable: Hello is 111

VaR o = Document. Body. createTextRange (); O. findtext ("world"); O. pastehtml = "<B> world </B>"; the HTML format can be replaced.

7.doc ument. Forms. Length

8. $ ("form1"). elements [0] is equivalent to $ ("form1") [0]

9. $ ("form1"). The elements of elements can be omitted, that is, access by index

Window. onload = function (){
VaR oform = $("form1 ");
VaR arr = oform; //. elements;
For (I = 0; I <arr. length; I ++ ){
If (ARR [I]. type! = "Hidden "){
Arr [I]. Focus ();
Break;
}
}
}

10. Window. onload = function (){
VaR arr = Document. getelementsbytagname ("input ");
For (VAR I = 0; I <arr. length; I ++ ){
If (ARR [I]. type = "text "){
Arr [I]. onfocus = function (){
This. Select ();
}
}
}
}

11. $ ("ddlfund"). Options. Add (New Option ("text", "value "));
$ ("Ww "). options [1]. text $ ("ww "). options [1]. value $ ("ww "). options [1]. index $ ("ww "). options. length $ ("ww "). selectedindex
$ ("Ww"). Options [1]. Selected $ ("ww"). Options. Remove (0)
Appendchild mobile node var F = $ ("ww"). Options [2]; $ ("ee"). Options. appendchild (f)
Insertbefore sorting node var F =$ ("ww "). options [2]; var Pref = $ ("ww "). options [3]; $ ("ww "). options. insertbefore (Pref, F );

12. createelement createtextnode getelementsbytagname appendchild tagname parentnode removechild

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.