关闭 "altertify" 确认模式后如何从按钮上移除焦点?

How to remove focus from button after closing the "altertify" confirm modal?

我有一个带有 :hover:focus css 属性 的按钮。将鼠标悬停在其上时,颜色变为红色。 现在,当我单击它时,会出现一个 Alertify 确认框,然后我按确定或取消颜色再次更改为红色,因为 :focus 属性。 单击“确定”或“取消”时如何取消绑定:focus

<html>
<head>
    <script src="https://cdn.jsdelivr.net/alertifyjs/1.8.0/alertify.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/alertifyjs/1.8.0/css/alertify.min.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/alertifyjs/1.8.0/css/themes/default.min.css"/>

</head>

<style>
.btn-test:hover,.btn-test:focus{
background-color:red;
}
</style>

<body>


<button class="btn-test">Click Me</button>


</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script>
$(".btn-test").click(function(){

 alertify.confirm('Confirmation', 'You clicked', function () {
                //do nothing
            }
            , function () {
                //do nothing
            });

});
</script>

</html>

你只需在 js 文件中添加此代码 $(".btn-test").blur();像这样:

$(".btn-test").click(function(){

        $(".btn-test").blur();        
   

 alertify.confirm('Confirmation', 'You clicked', function () {
                //do nothing
            }
            , function () {
                //do nothing
            });

});
.btn-test:hover,.btn-test:focus{
background-color:red;
}
<html>
<head>
    <script src="https://cdn.jsdelivr.net/alertifyjs/1.8.0/alertify.min.js"></script>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/alertifyjs/1.8.0/css/alertify.min.css"/>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/alertifyjs/1.8.0/css/themes/default.min.css"/>

</head>

<body>


<button class="btn-test">Click Me</button>


</body>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

</html>