-
이벤트 객체
.type
{mouseover|keypress|submit}
.button
.keyCode
{element}.onclick = function(event) {
if (!event) event = window.event;
var target = (event.target) ? event.target : event.srcElement;
...
};
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
a simple, cross-browser, addEvent function
1: W3C-recommended event model, addEventListener
2: Internet Explorer’s legacy attachEvent
var addEvent = (function () {
var filter = function(el, type, fn) {
for ( var i = 0, len = el.length; i < len; i++ ) {
addEvent(el[i], type, fn);
}
};
if ( document.addEventListener ) {
return function (el, type, fn) {
if ( el && el.nodeName || el === window ) {
el.addEventListener(type, fn, false);
} else if (el && el.length) {
filter(el, type, fn);
}
};
}
return function (el, type, fn) {
if ( el && el.nodeName || el === window ) {
el.attachEvent('on' + type, function () { return fn.call(el, window.event); });
} else if ( el && el.length ) {
filter(el, type, fn);
}
};
})();
// usage; addEvent(els, event, handler)
addEvent( document.getElementsByTagName('a'), 'click', fn);
* 마우스
click
Link, 버튼 요소
c.f. .click()
mousedown
Document, Link, Image, 버튼 요소
mouseup
dblclick
mousemove
mouseover
mouseout
* 키보드
keydown
keypress
keyup
* 인터페이스
-
focus
Text 요소, Window, 다른 모든 폼 요소
c.f. focus()
blur
c.f. .blur()
change
Select, 텍스트 입력 요소
contextmenu
load
unload
readystatechange
- 폼
reset
c.f. .reset()
submit
c.f. .submit()
-
resize
scroll
*
setTimeout()
clearTimeout()
참조 사이트:
http://net.tutsplus.com/tutorials/javascript-ajax/from-jquery-to-javascript-a-reference/