0

我有一个带有:hover:focuscss 属性的按钮。将鼠标悬停在其上时,颜色变为红色。现在,当我单击它时,会出现一个 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>
4

1 回答 1

2

您只需将此代码添加到 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>

于 2017-02-25T11:18:15.180 回答