|
Today, the system browser DOM event model of its deeper understanding of the future needs to be done in a day. First mark about the basic, deeper impression.
DOM element method to add an event handler:
1. Direct write tag js code
< Body onload = "var i = 1; alert (i);" >
< / Body >
2. Write a function name tag
< Head >
< Script >
function hi () {
alert ( "hi");
}
< / Script >
< / Head >
< Body onload = "hi ();" >
< / Body >
The essence of the above two methods are the same, is called inline mode, the lowest efficiency.
3.js script to specify the function to the event property
window.onload = hi;
This method can be better than the previous two kinds of number, called the traditional model. Inline mode and traditional mode are all DOM Level 0 event model, it is no longer recommended.
4. Do not rely on the element attribute listener
document.addEventListener ( "click", hi, true);
In this way it belongs to DOM Level 2 event model is more efficient than all of the aforementioned method. The new way is not dependent on a specific event processing property, you can register multiple handlers for any period of time any object. |
|
|
|