我想使用一个按钮来通过CSS的z-index
将
提到前面,再次按下该按钮时,我希望它恢复到原始状态。
这是我目前所拥有的代码,第一次改变很好用,但它不会恢复原样。
function thumbnail(){
if (document.getElementById("div").style.zIndex= -3){
document.getElementById("div").style.zIndex= -2;
}
if (document.getElementById("div").style.zIndex= -2){
document.getElementById("div").style.zIndex= -3;
}
}
=
表示赋值,用==
表示比较。 - onon15if
需要改为else
!否则两个代码块总是按顺序执行。当第一个更改为-2
时,第二个将立即将其更改回-3
。 - Michael Berkowskiif (...zIndex == -3) { ...zIndex = -2; }
注意if()
条件中的==
。 - Michael Berkowski