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 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探