我想检查我的id或类是否存在于表|JavaScript中



我有两个表,一个带有select选项,另一个带有results。当我从select中选择一个名称时,我会显示一些结果中的图像。当我从select中单击特定的一个名称时,我会更改css样式。这样做,但我只想在有id(div_new(或class(newA(的情况下这样做。也就是说,我想从结果中检查我的id或类是否存在于一个图像中,以更改我的风格。我该怎么做???

使用以下代码,它可以更改两个图像,而不是一个!

var playerAward = document.getElementById("my_select");
var playerAward2 = document.getElementById("my_select2");
var playerSelected = playerAward[playerAward.selectedIndex].value;
var playerSelected2 = playerAward2[playerAward2.selectedIndex].value;
if ((playerSelected == '.Athinodoros' && playerSelected2 == '.Dionisis' && $('#div_new').hasClass(".newA"))
|| (playerSelected == '.Dionisis' && playerSelected2 == '.Athinodoros' && $('#div_new').hasClass(".newA"))) {
$('.award').css('box-shadow', 'inset 0 0 0 1.5px black');
$('.award').css('background', 'rgb(255, 250, 240)');
$('.award').css('background', 'rgba(255, 250, 240, 0.5)');
}
<DIV Class="column">
<DIV ID="div_new" Class="award Athinodoros Dionisis newA">
<P><IMG SRC="Team BanListBanDark Room of Nightmare.jpg"><BR>
<LABEL Class="overlay">Dark Room of<BR>Nightmare</LABEL></P>
</DIV>
</DIV>
<DIV Class="column">
<DIV Class="award Athinodoros Dionisis">
<P><IMG SRC="Team BanListBanMoisture Creature.jpg"><BR>
<LABEL Class="overlay"><BR>Moisture Creature</LABEL></P>
</DIV>
</DIV>

之后我会这样做,但什么都没有。

var newAward = document.getElementById("div_new");
if ((playerSelected == '.Athinodoros' && playerSelected2 == '.Dionisis' && newAward.classList.contains("newA"))
|| (playerSelected == '.Dionisis' && playerSelected2 == '.Athinodoros' && newAward.classList.contains("newA"))) {
awardColor = awardColorChange();
} else if (playerSelected == "" && playerSelected2 == "") {
awardColor = awardColorChange2();
}

最新更新