简体   繁体   English

进行onclick操作并在“提交”按钮上提交表单的结果是什么?

[英]What is the outcome of having an onclick action that submits a form on a submit button?

Out of curiosity, I was wondering if there is an expected output when you have something like this: 出于好奇,我想知道当您遇到以下情况时是否有预期的输出:

    <input type="submit" onclick="document.formname.submit()">

I was working with a web page that someone created a few years ago and they had something similar to the above, for whatever reason. 我正在使用某人几年前创建的网页,无论出于何种原因,他们都具有与上述相似的内容。 I was testing the page on the other end of the submit button, which adds things to a mySQL database. 我正在测试“提交”按钮另一端的页面,该页面将内容添加到mySQL数据库中。 I found that it was occasionally adding everything twice, and was doing this more frequently the more items there are in the form. 我发现它偶尔会添加两次所有内容,并且表单中的项目越多,执行频率就越高。

Now I wonder if there is a way this is expected to work? 现在,我想知道是否有一种方法可以奏效? I mostly just want to make sure that my code on the other side of the submit button is working properly. 我主要只是想确保提交按钮另一侧的代码正常工作。 Why would this sometimes execute everything twice, and sometimes only once? 为什么这有时会执行两次所有操作,有时只能执行一次?

如果此标记在<form>内,则将表单中的值提交到服务器端,并且取决于标记的action属性

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

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