我想使用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")
答案 0 :(得分:1)
您需要使用这些属性的默认值来覆盖您设置的值
# Copyright 2017, Google, Inc.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# [START app_yaml]
handlers:
# Should probably be at the beginning of the list
# so it's not clobbered by a catchall route
- url: /datadog
script: gae_datadog.datadog.app
env_variables:
DATADOG_API_KEY: 'MY_KEY'
runtime: nodejs
env: flex
# [END app_yaml]
$(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;
}
答案 1 :(得分:0)
使用对象符号指定要删除的all the properties:
$("[class^=col-]").css({
width: "",
right: "",
margin: "",
position: ""
});
这里是一个例子:
$(document).ready(function() {
// remove color and background from style "attribute"
// leave everything else unchanged
$("[class^=col-]").css({
'color': '',
'background': ''
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="col-md-12" style="color: red; background: orange; position: relative;">some test</div>