doupin5667 2014-08-03 09:30
浏览 114
已采纳

单击PHP后禁用按钮

How can I disable a button after it has been clicked. And let it remain disabled. I tried using .prop('disabled', true); although it disables the button, however when i refresh the page then button became clickable again. Also if I have a list of it, it would disable other button as well which I do not want. Is there anyway to do it?

<table>
<tr>
<td id="milestone_1"> 
</td>
<td id="percentage_1">
</td>
<td>
<form id="pay1">
<input type="hidden" class="id_hidden" name="id_hidden">
<input type="hidden" class="paid_hidden" name="paid_hidden">
<input type="hidden" class="budget_hidden" name="budget">
<input type="hidden" id="percent1" name="percent">
<input type="submit" name="pay1" value="Pay">
</form>
</td>
</tr>

<tr>
<td id="milestone_2">
</td>
<td id="percentage_2">
</td>
<td>
<form id="pay2">
<input type="hidden" class="id_hidden" name="id_hidden">
<input type="hidden" class="paid_hidden" name="paid_hidden">
<input type="hidden" class="budget_hidden" name="budget">
<input type="hidden" id="percent2" name="percent">
<input type="submit" name="pay2" value="Pay">
</form>
</td>
</tr>

<tr>
<td id="milestone_3">
</td>
<td id="percentage_3">
</td>
<td>
<form id="pay3">
<input type="hidden" class="id_hidden" name="id_hidden">
<input type="hidden" class="paid_hidden" name="paid_hidden">
<input type="hidden" class="budget_hidden" name="budget">
<input type="hidden" id="percent3" name="percent">
<input type="submit" name="pay3" value="Pay">
</form>
</td>
</tr>

</table>


$("#pay1").submit(function(){
    $.ajax({
        type: "GET",
        url: "pay.php",
        data: $("#pay1").serialize(),
        success: function(data){

            $("#add_success").html(data);
            $("#add_err").html("");

        }
    });
    return false
});
$("#pay2").submit(function(){
    $.ajax({
        type: "GET",
        url: "pay.php",
        data: $("#pay2").serialize(),
        success: function(data){

            $("#add_success").html(data);
            $("#add_err").html("");

        }
    });
    return false
});
$("#pay3").submit(function(){
    $.ajax({
        type: "GET",
        url: "pay.php",
        data: $("#pay3").serialize(),
        success: function(data){

            $("#add_success").html(data);
            $("#add_err").html("");

        }
    });
    return false
});
  • 写回答

1条回答 默认 最新

  • donglun2024 2014-08-03 09:43
    关注

    I suggest to you use cookie to keep user state or data.
    simply you can use cookie in pure javascript by document.cookie object,

    javascript create cookie sample code:

    document.cookie="username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 GMT; path=/";
    

    read cookie:

    var x = document.cookie;
    

    also you can use this jQuery plugin for handle that

    cookie are very handy in PHP, so you can access cookie data by $_COOKIE global php variable.
    Personally i recommend you to keep tag selector in javascript variable and disable them on dom ready for other later requests.

    UPDATE

    For more secure implementation you can use server-side solutions, for this case you can use PHP session to keep data for showing or not showing elements to user.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀