, , , , someElement.onclick = function(e) { ... };, , , <input type="button" onclick="doSomething()">, . , .
(, ) , . , , .
, , .
myElement.onclick = function(e) { alert("Clicked"); };
, script, .
- , , Event (
window.event IE, ) return false
<input type="button" value="test" onclick="alert('Clicked');">
, , , , (.
http://peter.michaux.ca/articles/the-window-onload-problem-still ). , .
addEventListener/attachEvent
(attachEvent )
myElement.addEventListener("click", function(e) { alert("Clicked"); }, false);
, . addEventListener DOM 2.
addEventListener is a modern standard, with support in IE 9, which means that all current major browsers will support the release of IE 9
disadvantages
- It's a little tricky to implement cross browser correctly
- IE is
attachEventnot quite equivalentaddEventListener - In HTML source elements, handlers are usually not assigned until the document is loaded.
source
share