javascript - 使用 jquery 将 CSS 更改回默认值的问题
问题描述
我可以使用 Jquery 更改页面上的其他元素,但是当它使用 ::before 时,我似乎无法切换回默认的 css 类。
默认复选框css在行动
复选框选中的 css 正在运行
现在我有一个按钮,当它被点击时,应该将我的 css 重置为默认复选框 - 但它似乎对我不起作用......按钮保持绿色并且它不会向左移动..
**
单击按钮后示例
CSS -
<style>
.checkbox {
appearance: none;
border: 2px solid #ccc;
border-color: red;
border-radius: 20px;
cursor: pointer;
height: 24px;
outline: none;
position: relative;
transition: 0.3s;
width: 37px;
}
.checkbox::before {
background: red;
border-radius: 50%;
content: "";
height: 15px;
left: 0px;
position: absolute;
top: 2px;
transition: 0.3s ease-in-out;
width: 15px;
}
.checkbox:checked::before {
background: green;
transform: translateX(18px);
}
.checkbox:checked {
border-color: green;
}
.float-container {
border: 3px solid #fff;
padding: 20px;
}
.float-child {
border: 2px solid red;
padding: 20px;
text-align-last: center;
width: 100%;
}
.float-child-unknown {
border: 2px solid red;
padding: 20px;
text-align-last: center;
width: 100%;
}
</style>
JS-
function outsideModalClick() {
$(document).ready(function() {
document.getElementById('button').onclick = function() {
$('.float-child').css('border', '2px solid red');
$('.iconShow').toggleClass('iconhide');
$('.checkbox:checked::before').toggleClass('.checkbox::before');
$('.checkbox:checked').toggleClass('.checkbox');
}
})
}
编辑 - 仍然无法正常工作 - 没有应用 css
解决方案
推荐阅读
- cloud - 使用 IBM Watson Assistant - 英语以外的语言没有拼写检查选项。为什么?
- sql - MSSQL达到极限并更新
- mongodb - MongoDB连接被拒绝,安装
- angular - 无法覆盖 NgForm ViewChild 上的表单值
- xamarin.forms - xamarin 表单键盘涵盖的编辑器
- c++ - 我们应该如何在结构中添加功能?
- javascript - 悬停时显示一个人的元素
- sql - 如何在 SQL Server 中构建父子层次结构(从根开始)?
- qgis - QField - 输入字段的输入表单中的子菜单
- mysql - 如何从 GCP 上的实例备份恢复单个数据库?