Commonly used event binding methods under IE

1. html event

Description: The html event binding method under IE is equivalent to that of non-IE,

For details, please see: Commonly used event binding methods under non-IE_Not sweet blog-CSDN blog

2. dom0 event

Description: The dom0 event binding method under IE is equivalent to that of non-IE    

For details, please see:  Commonly used event binding methods under non-IE_Not sweet blog-CSDN blog

3. dom2 event

Description: The event bound by the attachEvent function under IE is called dom2 event     

Syntax: element node.attachEvent('type',listenFunc)    

illustrate:

(1) Parameter one indicates the type of binding event , there is on! !

(2) The second parameter indicates the monitoring function executed when the event occurs 

Notice:

        (1) AddEventListener is not recognized under IE, and attachEvent is not recognized under non-IE

               [After IE8, IE began to support the addEventListener method]

        (2) dom2 in IE can bind multiple functions to an event, and the execution sequence is executed in reverse order of the binding.

                div2.attachEvent('onclick', function () {console.log('1st click event 1');});

                div2.attachEvent('onclick', function () {console.log('2nd click event 2');});

                div2.attachEvent('onclick', function () {console.log('3rd click event 3');});

                div2.attachEvent('onclick', function () {console.log('4th click event 4');});

        (3) The capture event cannot be added to the event bound by the attachEvent method.

                [If you need to add capture events under IE, you need to support the version of IE addeventListener method]

Removed: Unbind the event through the detachEvent function under IE

[In versions after IE8, if the event is bound by the addeventListener method, you need to use removeeventListener to remove it]

Syntax: element node.detachEvent('type',listenFunc);

Note: Anonymous functions cannot be removed. If you want to remove them, you need to use the external function name .
          

Guess you like

Origin blog.csdn.net/weixin_55992854/article/details/118118905