我有一个带有:hover和:focus css属性的按钮。当悬停在它上面时,颜色会变成红色。现在,当我单击它时,会出现一个警报确认框,然后我按下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>发布于 2017-02-25 19:18:15
您只需将此代码添加到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>
https://stackoverflow.com/questions/42455155
复制相似问题