javascript - jQuery删除多个样式
问题描述
我想使用 jQuery 将我的所有 css 设置为 null。我知道你可以做到
$("[class^=col-]").css('width', '');
$("[class^=col-]").css('right', '');
$("[class^=col-]").css('margin', '');
$("[class^=col-]").css('position', '');
但是否可以在一个命令中完成,例如:
$("[class^=col-]").css('');
编辑:我查看了上面的帖子并看到了答案。
通过删除样式属性,它可以完美地工作$("[class^=col-]").removeAttr("style")
解决方案
您需要使用这些属性的默认值来覆盖您设置的值
$(document).ready(function() {
$("[class^=col-]").css({
'width': 'auto',
'position': 'inherit',
'margin': '0',
'right': '0'
});
});
.col-md-12 {
width: 10px;
position: fixed;
margin: 10px;
right: 10px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12">some test</div>
推荐阅读
- javascript - javascript eventListener 似乎不起作用
- java - OkHttp如何跳过FormBody表单元素编码
- flutter - 为什么 onTap 和其中的函数在 InkWell 中不起作用?
- c++ - cpprestsdk如何使用MARCO定义常量
- sql - LAG 函数只取前一个日期而不是按确切顺序运行
- html - 如何在 iframe 中创建书签链接?
- python - 如何将熊猫系列变成矩阵?
- mongodb - 猫鼬搜索大小写字母
- scala - Spark:如何将列的 ArrayType 中的单列收集到不同的数组?
- python - 当值是列表时,在 Pandas 中获取唯一值