Domobj.onkeydown = function (e) {
if (e) {
e ...
} else{
event ...
}
The above example: if the Firefox browser executes the statement within if, that is, use the E parameter to refer to the "event object".
If the IE browser executes the statement in else, it uses event to refer to the object.
This is an if judgment method that is used for compatibility with two browsers to use event objects.
Domobj.onkeydown = function (e) {
var oevent = e| | event;
Oevent ...
}
Example: By using the attribute of the "or" logical operator, it is automatically judged that the reference to the event object should be used.
Explanation: E | | event;
If it is IE browser, then E can not be used as a reference to the event object, False. Event is true, then event will assign value to var oevent = event;
On the contrary, in Firefox, the event cannot be used as a reference to the events object, False. E is true, then E will assign value to var oevent = e;
So no matter under that browser, Oevent can refer to the event object correctly! This style of writing is more elegant than the previous if () {}else{}!
The above is the entire content of this article, I hope to help you, thank you for the support of cloud habitat community!