How to access Event.target in IE9?

前端 未结 6 646
耶瑟儿~
耶瑟儿~ 2021-02-08 02:12

The HTML DOM object model defines an Event object with a target property.

Looking at MSDN, Microsoft documents a target property. They also document srcElem

6条回答
  •  温柔的废话
    2021-02-08 02:43

    The easy way to archive this is by using:

    var target = event.target || event.srcElement;
    
    • Avoid to use a ternary operator.

    The way this works is because:

    1. Test if event.target is a truthy which if does not exist in that browser will evaluate to false.
    2. If evaluates to false then it will move to the next operator which in this case is event.srcElement.

    And with this you will end up with the first value that is present on the current browser where the code is executed.

提交回复
热议问题