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