我遇到一些问题,在adventwindow< = day时将我的课程更改为活动状态,我希望它在true时将类从禁用更改为活动状态。如果有人能提供帮助那就太棒了!
var day = 5;
var adventwindow = 1;
if (adventwindow <= day) {
document.getElementsByClassName('disable').className = 'active';
}
.door {
color: #fff;
font-size: 70px;
position: absolute;
top: 0;
left: 0;
background-color: #91c1cc;
box-sizing: border-box;
border-top: 2px #eee dashed;
border-right: 2px #eee dashed;
border-bottom: 2px #eee dashed;
border-left: 1px #eee solid;
border-radius: 6px;
padding: 15px;
width: 130px;
height: 130px;
transform-origin: 0 40%;
transition: all 0.4s ease-in-out;
transform-style: preserve-3d;
text-align: center;
}
a.disable {
pointer-events: none;
cursor: default;
}
a.enable {
pointer-events: auto
}
<a class="disable" href="test">
<div class="door">1</div>
</a>
答案 0 :(得分:1)
getElementsByClassName
返回具有给定类名的元素集合。您可以按索引访问元素,从0开始。
document.getElementsByClassName('disable')[0].className = 'active';