Determine which element submitted a form from within onsubmit

后端 未结 5 762
小鲜肉
小鲜肉 2020-12-19 03:31

Is there a way to determine which element submitted a form from within an onsubmit handler? Trying to write a generic handler that knows which element was clicked. For examp

5条回答
  •  隐瞒了意图╮
    2020-12-19 04:15

    My fallback is walking the DOM to find all buttons that could cause a submit, but I'd like to avoid that.

    ...and adding click listeners to them to store the ‘last clicked’ button which is then read by the submit listener, right?

    I can't think of any other way, sorry.

提交回复
热议问题