单击拒绝/关闭后禁用两个按钮

发布于 2025-01-24 09:24:36 字数 1904 浏览 0 评论 0原文

我的任务是在单击“拒绝”按钮后能够禁用批准和返回按钮。拒绝按钮意味着关闭项目。这些是我的代码。有人可以帮助我找出如何禁用按钮吗?

<div class="text-center ">
    <button class="btn m-1 align-items-center btn-success text-center " id="approve">Approve</button>   
    <button class="btn btn-danger m-1 align-items-center text-center " id="clear" onclick="sweetalertrejects()">Reject</button>
    <button class="btn btn-secondary m-1 align-items-center text-center" id="return">Return</button>       
    </div>
    </div>
    </div>
                        <script>
                        function sweetalertrejects(){
                            swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {
                                icon: "info",
                                  buttons: {
                                    cancel: "Cancel",
                                    catch: {
                                      text: "Yes, close this task",
                                      value: "cancel",
                                    },
                                    
                                  },
                                })
                                .then((value) => {
                                  switch (value) {
                                 
                                
                                    case "cancel":
                                      swal("Closed!", "Task has been closed.", "success");
                                      break;
                                 
                                    default:
                                      swal("Task has not been closed.");
                                  }
                                });

                        }
                        </script>

My task is to be able to disable the approve and return buttons after clicking the reject button. Reject button means closing a project. These are my codes. Can anybody help me figure out how to disable the buttons?this is what the button looks like.

<div class="text-center ">
    <button class="btn m-1 align-items-center btn-success text-center " id="approve">Approve</button>   
    <button class="btn btn-danger m-1 align-items-center text-center " id="clear" onclick="sweetalertrejects()">Reject</button>
    <button class="btn btn-secondary m-1 align-items-center text-center" id="return">Return</button>       
    </div>
    </div>
    </div>
                        <script>
                        function sweetalertrejects(){
                            swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {
                                icon: "info",
                                  buttons: {
                                    cancel: "Cancel",
                                    catch: {
                                      text: "Yes, close this task",
                                      value: "cancel",
                                    },
                                    
                                  },
                                })
                                .then((value) => {
                                  switch (value) {
                                 
                                
                                    case "cancel":
                                      swal("Closed!", "Task has been closed.", "success");
                                      break;
                                 
                                    default:
                                      swal("Task has not been closed.");
                                  }
                                });

                        }
                        </script>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里南柯 2025-01-31 09:24:36

您可以通过ID获取按钮并将其禁用如下:

document.getElementById("approve").disabled = true;
document.getElementById("return").disabled = true;

这是整个代码

function sweetalertrejects(){
swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {
  icon: "info",
  buttons: {
    cancel: "Cancel",
    catch: {
      text: "Yes, close this task",
      value: "cancel",
    },

  },
})
  .then((value) => {
  switch (value) {


    case "cancel":
      swal("Closed!", "Task has been closed.", "success").then(()=>{
      document.getElementById("approve").disabled = true;
      document.getElementById("return").disabled = true;

      });
      break;

    default:
      swal("Task has not been closed.");
  }
});
}

You can get the buttons by id and disable them as follows:

document.getElementById("approve").disabled = true;
document.getElementById("return").disabled = true;

Here is whole code

function sweetalertrejects(){
swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {
  icon: "info",
  buttons: {
    cancel: "Cancel",
    catch: {
      text: "Yes, close this task",
      value: "cancel",
    },

  },
})
  .then((value) => {
  switch (value) {


    case "cancel":
      swal("Closed!", "Task has been closed.", "success").then(()=>{
      document.getElementById("approve").disabled = true;
      document.getElementById("return").disabled = true;

      });
      break;

    default:
      swal("Task has not been closed.");
  }
});
}
南烟 2025-01-31 09:24:36

您需要将className“ disable”包含在批准中&amp;返回按钮和您的JavaScript代码应该看起来像:

<script>
$('#clear').click(function() {

    swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {   
    icon: "info",
        buttons: {
        cancel: "Cancel",
        catch: {
            text: "Yes, close this task",
            value: "cancel",
        },
        
        },
    })
    .then((value) => {
        if(value){
            $('.disable').attr('disabled','disabled');
            swal("Closed!", "Task has been closed.", "success");
        }else{
            swal("Task has not been closed.");
        }
    });

});
</script>

You need to include classname "disable" to the Approve & Return button and your javascript code should look like this:

<script>
$('#clear').click(function() {

    swal("This button means closing the task. You will not be able to revert this action. Do you wish to continue?", {   
    icon: "info",
        buttons: {
        cancel: "Cancel",
        catch: {
            text: "Yes, close this task",
            value: "cancel",
        },
        
        },
    })
    .then((value) => {
        if(value){
            $('.disable').attr('disabled','disabled');
            swal("Closed!", "Task has been closed.", "success");
        }else{
            swal("Task has not been closed.");
        }
    });

});
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文