简体   繁体   English

提交按钮的事件触发序列

[英]Event firing sequence for a submit button

Say a submit button has a click event handler as well (yes, it's wrong, but that's really the code I'm working on). 假设一个提交按钮也有一个单击事件处理程序(是的,这是错误的,但这确实是我正在处理的代码)。

And the click handler sets a value in a field of the form that's about to be submitted. 点击处理程序在即将提交的表单的字段中设置一个值。

So when the submit button is clicked: 所以当点击提交按钮时:

  1. What will fire first, the form submit event or the click event? 首先会触发什么,表单提交事件或点击事件?
  2. Will the value set in the form field by the click event submitted to the server? 将click事件提交给服务器的表单字段中设置的值是多少? I think this depends on the answer to Q1. 我认为这取决于Q1的答案。 If the form is posted first, I'm guessing it won't. 如果首先发布表单,我猜它不会。

Note: I'm not looking for alternatives and advice. 注意:我不是在寻找替代方案和建议。 I know what the proper way of handling this will be. 我知道处理这个问题的正确方法是什么。 Just trying to understand the sequence of events and their implications. 只是试图了解事件的顺序及其含义。

  1. The click event on the submit button 提交按钮上的单击事件
  2. Yes, events resolve before default functionality, so the event runs and then the button submits the form (firing the submit event and then actually submitting the data). 是的,事件在默认功能之前解析,因此事件运行然后按钮提交表单(触发提交事件然后实际提交数据)。

First will be called event, there You have last chance f.ex to block form submitting. 首先将被称为事件,你有最后的机会f.ex阻止表单提交。 Then submit with changed values by event routine. 然后通过事件例程提交更改的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM