关闭“altertify”确认模式后,如何从按钮中移除焦点?

时间:2017-02-25 10:59:35

标签: javascript jquery html css3 alertifyjs

我有一个包含:hover:focus css属性的按钮。悬停在它上面时,颜色变为红色。 现在,当我点击它时会出现一个Alertify确认框,然后我按OK或由于: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>

1 个答案:

答案 0 :(得分:1)

你必须在js文件中添加这段代码$(&#34; .btn-test&#34;)。blur();像这样:

&#13;
&#13;
$(".btn-test").click(function(){

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

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

});
&#13;
.btn-test:hover,.btn-test:focus{
background-color:red;
}
&#13;
<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>
&#13;
&#13;
&#13;