douyin8809 2015-11-28 02:43
浏览 62

已禁用按钮可在另一个按钮上重新启用表单提交

I have three submit buttons inside FORM tags. They all have be of type="submit" because each manipulates the MySQL database in one way or another.

  • Load button
  • Dump button
  • Post button

When the Post button is clicked, I'm disabling the Load button:

<input type="submit" id="postpayment" name="postpayment" class="btn btn-primary" value="Post" onclick="document.getElementById('load').disabled='disable';">

But just as soon as it disables, it re-enables. How can I make it stay disabled? I've tried JavaScript and JQuery, but nothing works. If I change the Load button's type to type= "button", the it stays disabled. But because it's of type="submit", then it keeps reverting back to being enabled. This is driving me nuts! Can someone offer a solution to this? Thanks.

UPDATE: Per Deavid's suggestion, I've done this:

<script>
    $(function () {
        $(#postpayment).click(function (event) {
            (#load).attr('disabled', true);
            event.preventDefault();
        }) 
    });
</script>

When the Post button gets clicked, the Load button is suppose to be disabled and the default action prevented. But this isn't working. I know this JQuery function is wrong, but I don't know how to fix it.

  • 写回答

1条回答 默认 最新

  • dongyanpai2701 2015-11-28 04:13
    关注

    The simple solution is to add a return false; to your onclick

    <input type="submit" id="postpayment" name="postpayment" class="btn btn-primary" value="Post" onclick="document.getElementById('load').disabled='disable';return false;">
    

    However if you want to attach the click handler with jQuery like you did in your question, you can do it like so :

    $(function () {
        $('#postpayment').click(function (event) {
            event.preventDefault();
            $('#load').prop('disabled', true);
            // Your ajax here!
        });
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP