Invoke the default action of a specific event on an object

前端 未结 1 651
傲寒
傲寒 2021-01-13 19:03

I want a generic (cross browser) way to get the browser to execute the default action for an object for a specified event preferably without getting any att

1条回答
  •  心在旅途
    2021-01-13 19:40

    It appears that, at least for the click event, you can call .click() on the element in these browsers.
    This will have the element enact the default (as well as calling all listeners and the .onclick value, if defined).
    I don't know of any other defaults on DOM elements, would scroll need to be accounted for? Keypress? Maybe those exist as functions too, but I haven't tested.

    When I did test .click(), I noticed it obeyed any of the listeners returning false and did not fire the default, and the event did bubble (a listener I had on document fired too!).

    There may be no other alternative (I.e. calling the default directly, avoiding the listeners). And as for passing it an event object, the browser in question has the single global event thing going on, so maybe you can manipulate that and it wont have changed when executing .click().


    Adding as I find more information in my travels :)
    Furthermore, there is an doScroll() function, but I think it would be really hard to translate a given event into the string accepted by this method

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