Determine which element submitted a form from within onsubmit

后端 未结 5 778
小鲜肉
小鲜肉 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:18

    An alternative solution would be to move the event trigger from the form's submit event, to the submit element's onclick event, as such:

    In your handler function you can determine the submitting element simply by inspecting the event target's name, and if you need access to the form's information or other elements, you can get this from the submit elements "form" attribute.

提交回复
热议问题