dongyu4908 2016-07-13 11:03
浏览 146
已采纳

单击按钮提交表单并禁用按钮

Please I need your help, I want to disable a button on click and submit my form this is the code

            {{ form_start(form, {'attr': {'id': 'myForm'}}) }}

                    //....... NOT important

                {{ form_rest(form) }}

                <button class="btn-large waves-effect waves-light fullwidth" type="submit" id="monBttn"  onclick="myFunction()" name="action"
                        value="{{ 'registration.submit'|trans({}, 'FOSUserBundle') }}">
                    <i class="material-icons left">save</i>
                    Enregistrer
                </button>
            {{ form_end(form) }}

In my button i called a fuction this is the code

<script>
    function myFunction() {
        buttn = document.getElementById("monBttn");
        document.getElementById("myForm").submit();
        buttn.setAttribute('disabled','disabled');
    }
</script>

my script does not work the button is disabled but it does'nt submit the value Thanks in advance :)

  • 写回答

3条回答 默认 最新

  • duanshang7007 2016-07-13 11:28
    关注

    I have create one demo. It is working fine.

    HTML

    <form>
        <input type="submit" value="submit" id="submit">
    </form>
    

    SCRIPT

    $(function(){
            document.getElementById("submit").onclick = function() {
                this.disabled = true;
            }
        });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

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