我有一个带有: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>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句