使用javascript激活类

使用javascript激活类,javascript,css,Javascript,Css,问题是这个班只上一次课 css Javascript function win(userChoice, computerChoice) { const result = document.getElementById('p_result'); result.textContent = 'You Win!'; userScore++; userScore_span.textContent = userScore; document.getElementBy

问题是这个班只上一次课

css

Javascript

function win(userChoice, computerChoice) {
    const result =  document.getElementById('p_result');
    result.textContent = 'You Win!';
    userScore++;
    userScore_span.textContent = userScore;
    document.getElementById(userChoice).classList.add('green-glow')
}
我想在每次用户获胜时激活“绿色发光”类


谢谢你的帮助

你错过了比赛!
var-element=document.getElementById(“userChoice”);

元素。类列表。添加(“绿色辉光”)我无法完整地再现你关于
userChoice,computerChoice

但是给你做了一个样品,希望对你有所帮助

函数winUser(){
document.getElementById(“用户”).classList.add(“绿色发光”);
设置超时(()=>{
document.getElementById(“用户”).classList.remove(“绿色发光”);
},1000);//动画时间
}
函数winPc(){
document.getElementById(“pc”).classList.add(“绿色发光”);
设置超时(()=>{
document.getElementById(“pc”).classList.remove(“绿色发光”);
},1000);//动画时间
}
。绿色发光{
动画名称:绿色发光;
动画持续时间:0.5s;
动画计时功能:放松;
}
@关键帧绿色发光{
0% {
边框:4倍实心rgba(6724397);
盒影:0 0 10px#31b43a;
}
50% {
边框:4倍实心rgba(21255,0,0.822);
盒影:0 10px#29f036;
}
100% {
边框:4倍实心rgba(13255,45,0.685);
盒影:0 0 10px#31b43a;
}
}

使用者
个人计算机
赢得用户

Win PC
也请提供html什么是“某物”?您想何时添加此类?请熟悉。
function win(userChoice, computerChoice) {
    const result =  document.getElementById('p_result');
    result.textContent = 'You Win!';
    userScore++;
    userScore_span.textContent = userScore;
    document.getElementById(userChoice).classList.add('green-glow')
}