如何通过单击按钮更改彩色框的不透明度?

how to change the opaqueness of a colored box by click a button?

我有一个让盒子变淡的作业,这意味着点击一个按钮来改变彩色盒子的不透明度。但我无法让它发挥作用。下面是一些编码。怎么了?非常感谢。

<button id="button3">Fade</button>

document.getElementById("button3").addEventListener("click", function(){
  document.getElementById("box").style.Opacity = "0.5";
});

问题

  1. 您正在尝试访问 boxid 的元素

  2. 所说,javascript区分大小写,意思是Opacity应该是opacity

修复以上问题

document.getElementById("button3").addEventListener("click", function(){
  document.getElementById("button3").style.opacity = "0.5";
});
<button id="button3">Fade</button>

多读书

Note: JavaScript is case sensitive — myVariable is a different variable to myvariable. If you are getting problems in your code, check the casing!