gpt4 book ai didi

javascript - 用 css 覆盖颜色和背景

转载 作者:太空宇宙 更新时间:2023-11-04 02:44:16 32 4
gpt4 key购买 nike

我必须更改网站中所有元素的颜色和背景。我这样做:

var color_text = ["initial","#00FF21","#fff"];
var color_background = ["initial","#f00","#000"];
var ile = 1;

$('.kontrast').click(function () {
$('#main').css("color", color_text[ile]);
$('#main').css("background", color_background[ile]);
$('a#main').css("color", color_text[ile]);
ile = (ile+1) % 3;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a class="kontrast" href="#">Contrast</a>


<div id="main">
<h3>A little bit of text </h3>
<p>z A little bit of text .</p>
<p><strong>A little bit of text</strong></p>
<p>A little bit of text</p>
<p><a href="#">Download .pdf</a></p>
</div>

在这种情况下,我无法为元素更改它。它也不适用于我网站中的 h3 元素。我怎样才能完全覆盖所有元素?我试过这样做

$('a#main').css("color", color_text[ile]);

但是没用

最佳答案

您可以将 jquery 选择器更改为“main *”

var color_text = ["initial","#00FF21","#fff"];
var color_background = ["initial","#f00","#000"];
var ile = 1;

$('.kontrast').click(function () {

$('#main *').css("color", color_text[ile]);
$('#main *').css("background", color_background[ile]);
$('a#main').css("color", color_text[ile]);
ile = (ile+1) % 3;
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<a class="kontrast" href="#">Contrast</a>


<div id="main">
<h3>A little bit of text </h3>
<p>z A little bit of text .</p>
<p><strong>A little bit of text</strong></p>
<p>A little bit of text</p>
<p><a href="#">Download .pdf</a></p>
</div>

关于javascript - 用 css 覆盖颜色和背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34104810/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com