JS Event Summary

Source: Internet
Author: User

1, Event object
    e | | Window. Event//ie
2, take the mouse click coordinates with scroll bar
    var top = Document.documentElement.scrollTop | | Document.body.scrollTop; //chorme
        var x = top + e.clientx;  //visual area coordinates
3, get screen coordinates
    
    E.screenx    E.screeny
4, Shiftkey Altkey Ctrlkey
5,onkeydown/onkeyup keycode  return ASCII code is case-insensitive  
    
    
        chorom/ie return KeyCode Support case
        CharCode  return character encoding
7, get the event source
   
    target = E.target | | E.srcelement
    
        Target.tagname
        
    E.type
8, Event Flow
    FF first captures and then bubbles
    
    IE  bubbling
9, Cancel bubbling
    true;
Ten, AddEventListener
    1, resolved call two times, will not be overwritten (ie upside down)
     Window.addeventlistener (' Load ',function() {
             Alert (' LV ');
     },false);
     Window.addeventlistener (' Load ',function() {
         Alert (' miss.lv ');
     },false);
    FF LV miss.lv
    IE miss.lv LV
    
    2, resolve to pass two identical functions, execute only once (ie does not resolve, pass the same two functions)
    Window.addeventlistener (' Load ', init,false);
        Window.addeventlistener (' Load ', init,false);
    this point to window)
    
    Window.attachevent (' Load ',function() {
            var box = document.getElementById (' box ');
            Box.attachevent (' onclick ',function() {
             Alert (this ===window);  //true
            })
    })
    function addevent (Obj,type, FN) {
            Obj.attachevent (' on 'function() {
                Fn.call (obj,arguments);
        })
    }
addevent (window,' Load ',function() {
    var box = document.getElementById (' box ');
    addevent (box,' click ',function() {
        Alert ( this = = box);
    })
})
    
   4, add an additional method that does not overwrite
One by one,    move into  e.ralatedtarget e.fromelement mouseover
    Remove the  e.ralatedtarget e.toelement   mouseout
12, block default behavior
    E.preventdefault ();
        false;
    false, because return false can only be placed in front, and the back cannot be executed.
13, Roller Events
      Non-FF        MouseWheel
      FF     Dommousescroll
      
function (e) {
        var this. getEvent (e);
        if (E.wheeldelta) {
            return E.wheeldelta;
        }Else{
            return -e.detail*40;
        }
    }
    

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.