In the Web, the DOM event section mentions how to implement event handling in Chrome,ie, and a lower version of the browser, and here's a summary:
1. Non-IE browsers support AddEventListener and RemoveEventListener.
2.IE browsers (low version) support Attachevent and detachevent, but other browsers are not supported.
3. Each browser (regardless of the lower version) supports DOM0-level events, but one drawback is that it cannot be processed repeatedly.
So we're going to have to do the cross-browser processing, we need to use the handle operation, here in Click for example, look at the code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
A handle AddHandler is encapsulated in the variable eventutil, which is used to pass the event to be implemented, the required parameter is element, type (event, here is the click action), Handler (response function)
Then make an If judgment:
If the execution of AddEventListener is performed directly, the first two parameters of the AddEventListener are the events just passed in and their responses, and the last false indicates bubbling with events;
If you cannot perform the above, but can execute attachevent, ie, then call attachevent, note that the type in the parameter needs to be preceded by "on", because we passed to the handle is omitted in the But in the attachevent parameter on can not be omitted, such as Click to be added to the onclick;
The last compatibility process is direct element.onclick, where the brackets are used instead of the dots, and also to match the add on. Element. " On "+type This syntax is wrong, so use the brackets instead.
Click the button with a different browser to pop out of the window.
In the same way, we can add a delete handle, and then click the button to not react:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
Cross-browser event handling