var eventControl = 

{

add:function(elem, eventType, handler)

{

eventType = eventType.replace('on', '');

if(elem.addEventListener)

{

elem.addEventListener(eventType, handler, false);

}

else if(elem.attachEvent)

{

eventType = 'on' + eventType;

elem.attachEvent(eventType, handler);

}

},

remove: function(elem, eventType, handler)

{

eventType= eventType.replace('on', '');

if(elem.removeEventListener)

{

elem.removeEventListener(eventType, handler);

}

elseif(elem.detachEvent)

{

eventType = 'on' + eventType;

elem.detachEvent(eventType, handler);

}

}

};


eventControl.add(window, 'load', 

function(event)

{

var time = 0;

var button = document.getElementsByTagName('button')[0];

eventControl.add(button, 'click', 

function(event)

{

if(time > 0)

{

document.getElementById('msContent').innerHTML = event.timeStamp - time;

}

time = event.timeStamp;

});

});


11-1_EventAttr.js


반응형

'Programming > JavaScript' 카테고리의 다른 글

[JavaScript] 11-3_KeyboardEvent.js  (0) 2016.12.08
[JavaScript] 11-2_MouseEvent.js  (0) 2016.12.08
[JavaScript] 11-0_EventHandling.html  (0) 2016.12.08
[JavaScript] 7-8_modifyContent.js  (0) 2016.12.08
[JavaScript] 7-7_attrObj.js  (0) 2016.12.08

+ Recent posts