Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/88.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用document.querySelector('..').style。更改不同div的*two*CSS属性_Javascript_Html_Css - Fatal编程技术网

Javascript 使用document.querySelector('..').style。更改不同div的*two*CSS属性

Javascript 使用document.querySelector('..').style。更改不同div的*two*CSS属性,javascript,html,css,Javascript,Html,Css,作为后续行动。我有以下脚本: document.querySelector('.clickme').addEventListener('click', function() { this.style.color = '#f00'; this.style.backgroundColor = '#fff'; }); …这意味着当单击/点击div.clickme时,脚本将更改.clickme自身的颜色和背景颜色属性。现在,取而代之的是,我需要脚本不要更改。clickme自己的

作为后续行动。我有以下脚本:

 document.querySelector('.clickme').addEventListener('click', function() {
     this.style.color = '#f00';
     this.style.backgroundColor = '#fff';
 });
…这意味着当单击/点击div.clickme时,脚本将更改.clickme自身的颜色和背景颜色属性。现在,取而代之的是,我需要脚本不要更改。clickme自己的属性,而是页面上另一个元素的颜色和背景颜色,我们称之为div类。zebra。如何修改脚本以实现这一点?单击/点击的目标仍然是。单击我

您可以在单击事件处理程序中使用document.querySelector.zebra

document.querySelector('.clickme').addEventListener('click', function() {
     this.style.color = '#f00';
     this.style.backgroundColor = '#fff';
     document.querySelector('.zebra').style.color = 'blue';
     document.querySelector('.zebra').style.backgroundColor = 'grey';
 });
document.querySelector'.clickme'.addEventListener'click',函数{ this.style.color='f00'; this.style.backgroundColor='fff'; document.querySelector.zebra.style.color='blue'; document.querySelector.zebra.style.backgroundColor='grey'; }; 点击我
Zebra使用document.querySelector.Zebra找到另一个元素,并更改其颜色和背景色:

document.querySelector('.clickme').addEventListener('click', function() {
    let zebra = document.querySelector('.zebra')
    zebra.style.color = '#f00';
    zebra.style.backgroundColor = '#fff';
});

希望这会有所帮助。

通过另一个对document.querySelector的调用找到另一个元素。