e.srcElement is undefined in firefox?

前端 未结 3 988
野趣味
野趣味 2021-01-12 07:54

I am developing a website and now am testing in all browsers, I am currently testing in firefox and have found and error when using event.sourceElement?

What i need

相关标签:
3条回答
  • 2021-01-12 08:23

    Simple as

    var val= (e.srcElement||e.target).value;
    console.log(val);
    
    0 讨论(0)
  • 2021-01-12 08:26
    function getTarget(obj) {
        var targ;
        var e=obj;
        if (e.target) targ = e.target;
        else if (e.srcElement) targ = e.srcElement;
        if (targ.nodeType == 3) // defeat Safari bug
            targ = targ.parentNode;
        return targ;
    }
    

    Will return the target for all browsers if you pass it e

    from:- http://www.quirksmode.org/js/events_properties.html

    0 讨论(0)
  • 2021-01-12 08:28

    in firefox simply call e.target to work. instead of e.srcElement[which works only in IE]

    0 讨论(0)
提交回复
热议问题