【问题标题】:How to disable button permanently after click ,buttons created from server data using loops?单击后如何永久禁用按钮,使用循环从服务器数据创建的按钮?
【发布时间】:2021-12-22 04:27:17
【问题描述】:

我有一个使用数据库创建的页面上的按钮列表,我想永久禁用用户单击按钮。页面加载后按钮也应该处于禁用模式。

<div class="panel-group" id="posts">  
            <?php  
            while($row = $query->fetch(PDO::FETCH_ASSOC))
            {  
            ?>  
              <button id='registedButton' type='button' onclick='getButtonDataId(this)' data-id=<?php echo $row["Acronym"]; ?>>Applied</button> 
             }

【问题讨论】:

    标签: javascript php html mysql


    【解决方案1】:
    <div class="panel-group" id="posts">  
            <?php  
            while($row = $query->fetch(PDO::FETCH_ASSOC))
            {  
            ?>  
              <button id='registedButton_<?php echo $row["Acronym"]; ?>' type='button' class="registedButton" data-id=<?php echo $row["Acronym"]; ?>>Applied</button> 
             <?php } ?>
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    
    <script>
    $(document).ready(function(){
       $(".registedButton").each(function() {
            var getCookieName = $(this).attr('id');
            if(getCookie(getCookieName)){
               $(this).prop('disabled',true);
            }
       });
    });
    $('.registedButton').on('click', function(e) {
     var cookieName = $(this).attr('id');
     var eCookie = setCookie(cookieName, 'setVal');
     e.preventDefault();
     $(this).prop('disabled',true);
    });
    </script>
    

    【讨论】:

    • 为什么你改变了 thi id='registedButton_'
    • 它会禁用特定按钮还是每个按钮。此外,重新加载后按钮也应该禁用。
    • id='registedButton_' 总是应该是唯一的
    • 你必须使用 setCookie('cookieName', cookieValue);如果需要在重载后维护...
    • 我的主要目的是实现 setCookie('cookieName', cookieValue);这是我的代码。
    猜你喜欢
    • 2020-12-13
    • 2019-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-06
    • 1970-01-01
    相关资源
    最近更新 更多