dtwzwmv87399 2018-08-14 08:14
浏览 106

html表单:阻止发送时重新提交

I have this form:

<form action="" method="post" name="my_form">
    <input type="text" name="my_input">
</form>

You can write some text and the submit by pressing the enter key.

My problem: When you press the enter key multiple times, it'll also sent multiple times to my server.

There are solution like this:

onsubmit="my_button=true;return true;"

But these solutions require a submit button.

Is there a way to do this without adding a (hidden) submit button?

  • 写回答

4条回答 默认 最新

  • dongzhe3573 2018-08-14 08:23
    关注

    Like this (untestet):

        var formSubmitted = false;
        document.getElementById('my-form').addEventListener('submit', function(){
        if(formSubmitted === false) {
            formSubmitted = true;
            return true;
        }
        return false;
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器