Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.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中的filter:brightness应用于一组图像元素_Javascript_Css - Fatal编程技术网

我试图将JavaScript中的filter:brightness应用于一组图像元素

我试图将JavaScript中的filter:brightness应用于一组图像元素,javascript,css,Javascript,Css,var-brightness=document.getElementById(“亮度”); trash.addEventListener(“单击”,函数(){ 亮度.style.filter=“亮度(100%)”; }); 正如评论中的另一个人所说,您需要使用类。。。这很有效 var trash=document.getElementById(“垃圾”); trash.addEventListener(“单击”,函数(){ var elems=document.queryselectoral(

var-brightness=document.getElementById(“亮度”);
trash.addEventListener(“单击”,函数(){
亮度.style.filter=“亮度(100%)”;
});

正如评论中的另一个人所说,您需要使用类。。。这很有效

var trash=document.getElementById(“垃圾”);
trash.addEventListener(“单击”,函数(){
var elems=document.queryselectoral(“.brightness”);
对于(var i=elems.length;i--;){
元素[i].style.filter=“亮度(1.7)”;
}
});


顺便说一下,以前的亮度是45%;我正在尝试将它们恢复到100%。
id
必须是唯一的,并且每个元素只有一个
id
。为什么有多个元素都具有
id
亮度
?你应该用一个类来代替。哦,好吧,我想是的。如果我使用类,我如何分配它们?我还没有使用或学习getElementsByClassName。我知道它的工作方式与getElementById不同。非常感谢!我会记住这一点。我能问一下为什么你是在循环中而不是在++?这只是一种快速编写for循环的方法-很多人认为在变量中缓存数组的长度比调用[]快。每次。。。我不确定这个消息来源有多可靠。哦,我明白了。谢谢你的有用提示。