Gets the event object compatible ie wording
1 var obox = document.querSelector(".box"); 2 3 obox.onclick = function(eve) { 4 var e = eve || window.event //ie只支持window.event 5 console.log(e); 6 }
Stop the event bubbling ie compatible wording
. 1 function stopBubble (E) { // incoming event object 2 IF (e.stopPropagation) { . 3 e.stopPropagation (); . 4 } the else { . 5 e.cancelBubble = to true ; // if ie, using e.cancleBubble . 6 } 7 }
Listening bindings compatible ie wording
. 1 function addEvent (ELE, type, CB) { // element object event type function 2 IF (ele.addEventListener) { . 3 ele.addEventListener (type, CB) // IE is not supported . 4 } the else IF (ele.attachEvent) { . 5 ele.attachEvent ( "ON" + type, CB) // only ie9 support . 6 } the else { . 7 ELE [ "ON" + type] = CB; // do not support, using the assignment bindings 8 } 9 }
Ie compatible with the wording unbind events
. 1 function removeEvent (ELE, type, CB) { // element object event type function 2 IF (ele.removeEventListener) { . 3 ele.removeEventListener (type, CB) // IE is not supported . 4 } the else IF (ele.detachEvent) { . 5 ele.detachEvent ( "ON" + type, CB) // IE support . 6 } the else { . 7 ELE [ "ON" + type] = null ; // do not support, using the binding event to delete the assignment of formula 8 } 9 }